Last active
June 26, 2018 09:11
-
-
Save MarounMaroun/26291dafb66563c471ab103245d0af9a to your computer and use it in GitHub Desktop.
Add branch name to commit message githook
This file contains hidden or 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
mkdir -p ~/.git_hooks | |
# make it executable | |
chmod a+x ~/.git_hooks/commit-msg | |
# --------------------------- | |
# vi ~/.git_hooks/commit-msg: | |
NAME=$(git branch | grep '*' | sed 's/* //') | |
DESCRIPTION=$(git config branch."$NAME".description) | |
echo "$NAME"': '$(cat "$1") > "$1" | |
if [ -n "$DESCRIPTION" ] | |
then | |
echo "" >> "$1" | |
echo $DESCRIPTION >> "$1" | |
fi | |
# --------------------------- | |
git config --global init.templatedir '~/.git_hooks' | |
# and git init (only once) in each project you want to use the hook | |
git init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment