Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Created July 13, 2020 17:37
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 Trass3r/73cd463311654a915171c117506ab168 to your computer and use it in GitHub Desktop.
Save Trass3r/73cd463311654a915171c117506ab168 to your computer and use it in GitHub Desktop.
Git hook that inserts the git branch name into the commit message, useful for ticket references
#!/bin/bash
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
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment