Instantly share code, notes, and snippets.

@sapegin /git.md Secret
Last active Nov 12, 2015

Embed
What would you like to do?

Branching

We’re following Git Flow with almost default settings:

  • production-ready code: master;
  • ongoing development: develop;
  • feature branches: feature/myfeautre_IZM-1234;
  • release branches: release/vX.X.X.

The only exception is feature branch name should contain feature name and Jira ticket number.

Commit messages

Commit messages should look like this:

[IZM-1234 myfeature] Add really awesome feature.

There’s a Git hook that will adds a ticket number to your commit messages. To install it:

cd ~/izumi/izumi-app
ln -s -f ../../githooks/prepare-commit-msg .git/hooks/prepare-commit-msg

More information

#!/bin/bash
# Prepends commit message with a ticket number:
# feature/mytask_IZM-1234 -> "[IZM-1234] My awesome commit."
TICKET_PREFIX="IZM"
BRANCH_FULL_NAME=$(git symbolic-ref --short HEAD)
# Not a feature branch
if [[ "$BRANCH_FULL_NAME" != "feature/"* ]]; then
exit
fi
# Strip prefix
BRANCH_NAME="${BRANCH_FULL_NAME##*/}"
# Extract ticket number and feature name
TICKET_NUMBER=$(echo $BRANCH_NAME | sed -n "s/.*\($TICKET_PREFIX-[0-9]\)/\1/p")
FEATURE_NAME=$(echo $BRANCH_NAME | sed -n "s/\(.*\)_$TICKET_NUMBER/\1/p")
# Ticket number wasn't specified
if [[ -z "$TICKET_NUMBER" ]]; then
exit
fi
# Commit message already contains the ticket number
COMMIT_MESSAGE="$(cat $1)"
if [[ "$COMMIT_MESSAGE" == *"[$TICKET_NUMBER"* ]]; then
exit
fi
sed -i.bak -e "1s/^/[$TICKET_NUMBER $FEATURE_NAME] /" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment