Skip to content

Instantly share code, notes, and snippets.

@rajavijaysingh
Forked from shytikov/commit-msg
Created August 7, 2018 12:36
Show Gist options
  • Select an option

  • Save rajavijaysingh/8413ffe4138984d3df90ec118ec457d7 to your computer and use it in GitHub Desktop.

Select an option

Save rajavijaysingh/8413ffe4138984d3df90ec118ec457d7 to your computer and use it in GitHub Desktop.
commit-msg hook script
#!/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
@rajavijaysingh
Copy link
Author

To automatically add the branch name to the commit msg.
Please follow the below steps

Attach the attached file to your existing repo directories in the below folder
/.git/hooks

And to handle for any future repos add the attached git hook to the git installation template folder
C:\Program Files\Git\mingw64\share\git-core\templates\hooks

If using eclipse to commit then add the below to your path directory and restart eclipse
C:\Program Files\Git\usr\bin

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