Skip to content

Instantly share code, notes, and snippets.

@MarounMaroun
Last active June 26, 2018 09:11
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 MarounMaroun/26291dafb66563c471ab103245d0af9a to your computer and use it in GitHub Desktop.
Save MarounMaroun/26291dafb66563c471ab103245d0af9a to your computer and use it in GitHub Desktop.
Add branch name to commit message githook
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