Skip to content

Instantly share code, notes, and snippets.

@Jakobovski
Created December 7, 2015 10:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jakobovski/2aa9791a1ddff7e7efdd to your computer and use it in GitHub Desktop.
Save Jakobovski/2aa9791a1ddff7e7efdd to your computer and use it in GitHub Desktop.
Script to automatically add the branch name and description to commit messages.
#!/bin/sh
# Automatically adds branch name and branch description to every commit message.
# Rename .git/hooks/prepare-commit-msg.sample to prepare-commit-msg, paste the script and make the file executable.
# Modified from: http://stackoverflow.com/questions/5894946/how-to-add-gits-branch-name-to-the-commit-message
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment