Skip to content

Instantly share code, notes, and snippets.

@svillafe
Created July 5, 2017 15:48
Show Gist options
  • Save svillafe/85211cfe4854130abfb33ece47968079 to your computer and use it in GitHub Desktop.
Save svillafe/85211cfe4854130abfb33ece47968079 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
TEXT=$(cat "$1" | sed '/^#.*/d')
if [ -n "$TEXT" ]
then
echo "[$NAME]"' '$(cat "$1" | sed '/^#.*/d') > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
else
echo "Aborting commit due to empty commit message."
exit 1
fi
@svillafe
Copy link
Author

svillafe commented Jul 5, 2017

Remember to turn this file as executable. You can do this by running: chmod +x .git/hooks/prepare-commit-msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment