Created
January 18, 2016 03:36
-
-
Save warrenca/120845f3a481e3b083c5 to your computer and use it in GitHub Desktop.
Auto-add git branch on commit
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/sh | |
# This file must be executable | |
# chmod u+x .git/hooks/prepare-commit-msg | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then | |
# use ~ instead of / to accomodate branch names with forward slash | |
# e.g. branch name "user/feature-name-" | |
sed -i.bak -e "1s~^~[$BRANCH_NAME] ~" $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment