Last active
July 13, 2022 21:23
-
-
Save joaorafaelm/4fedbd643fba2804df0117ac2b170da7 to your computer and use it in GitHub Desktop.
Prefix your commits with the branch name
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
curl -o '.git/hooks/prepare-commit-msg' https://gist.githubusercontent.com/joaorafaelm/4fedbd643fba2804df0117ac2b170da7/raw/prepare-commit-msg && chmod +x .git/hooks/prepare-commit-msg |
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) #Somthing like refs/heads/myBranchName | |
branchName=${branchPath##*/} #Get text behind the last / of the branch path | |
firstLine=$(head -n1 $1) | |
if [ -z "$firstLine" ] ;then #Check that this is not an amend by checking that the first line is empty | |
sed -i '.bak' "1s/^/\[$branchName\] /" $1 #Insert branch name at the start of the commit message file | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment