Skip to content

Instantly share code, notes, and snippets.

@rpowis
Created April 25, 2013 18:55
Show Gist options
  • Save rpowis/5462155 to your computer and use it in GitHub Desktop.
Save rpowis/5462155 to your computer and use it in GitHub Desktop.
prepare-commit-msg git hook that adds the branch name to the end of the commit message
#!/bin/sh
#
# This hook will append the current branch name to
# the commit message if it's not already there.
ref=$(git symbolic-ref HEAD 2> /dev/null)
branch=${ref#refs/heads/}
if [[ "$branch" != "master" ]]; then
grep -qa "$branch" "$1" || echo "\n[Branch: $branch]" >> "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment