Skip to content

Instantly share code, notes, and snippets.

@kylieCat
Last active October 15, 2015 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylieCat/4d5525fe50c37566ffa5 to your computer and use it in GitHub Desktop.
Save kylieCat/4d5525fe50c37566ffa5 to your computer and use it in GitHub Desktop.
Git hook to append branch name to commit message
# Automatically adds the JIRA ticket number to the end of every commit message.
# This will work provided your branch is named in the form [a-zA-Z]{3}-[0-9]{3,}
# Place this file in PROJECT/.git/hooks and make it executable chmod +x path/to/file
# Example:
# [BND-1234] <--- This is a branch name
# $ git commit -am "This is my message"
# [BND-1234 1edab53] This is my message [BND-1234]
#
# [BND-1234-This-Branch-Has-A-Description] <--- This is a branch name
# $ git commit -am "This is my message"
# [BND-1234 1edab53] This is my message [BND-1234]
NAME=$(git branch | grep '*' | sed 's/* //' | grep -o '[a-zA-Z]\{3,\}-[0-9]\{3,\}')
echo $(cat "$1") "[$NAME]" > "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment