Last Updated: May 16, 2018
·
1.405K
· trybeee

Github issue number and commit message

I use Github Issues and often i forget to add issue number to commit message. Usually i prepend message with #some-number. i.e. current branch '308-context-help' and commit message 'fix bug' will result in '#308 fix bug').

So i decide to use git's commit-msg hook for that task:

#!/bin/sh

if [ "$NOPREFIX" ]; then
  exit 0
fi

number=$(git branch | grep '*' | sed 's/* //' | cut -d'-' -f 1) 
if [[ "$number" =~ ^[0-9]+$ ]] ; then
  echo '#'"$number"' '$(cat "$1") > "$1"
fi

Just put that code to .git/hooks/commit-msg and you're done.

https://gist.github.com/trybeee/5005684