Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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