Skip to content

Instantly share code, notes, and snippets.

@tianskylan
Created November 29, 2016 21:34
Show Gist options
  • Save tianskylan/92c94c73e0434c61a6e2d70cc7972ddd to your computer and use it in GitHub Desktop.
Save tianskylan/92c94c73e0434c61a6e2d70cc7972ddd to your computer and use it in GitHub Desktop.
Prefix branch name to commit messages
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# I made this a commit-msg hook to get it working with GitUp client. Otherwise, prepare-commit-msg hook should work as well.
#
# Usage:
# 1. Save this file in PROJECT_NAME/.git/hooks, with name `commit-msg`
# 2. chmod 755 commit-msg
# 3. Profit.
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
TEXT=$(cat "$1" | sed '/^#.*/d')
if [ -n "$TEXT" ]
then
echo "[$NAME] $TEXT" > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
else
echo "Aborting commit due to empty commit message."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment