Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Git hook that inserts the git branch name into the commit message, useful for ticket references
branchPath=$(git symbolic-ref -q HEAD) # refs/heads/branchName
branchName=${branchPath##*/} # get text behind the last /
# check that this is not an amend by checking that the first line is empty
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ; then
# insert template at the start of the commit message file
sed -i "1s/^/$branchName \n/" $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.