Created
July 13, 2020 17:37
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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