So my branch is named after bugtracker ticket number, something like \"issue-1234\", and we have a convention to always write down ticket number in commit message. I\'m wond
You can as well use prepare-commit-msg
hook, which accepts more parameters than commit-msg
. Then you can check if the message is coming from a file, a template, etc to avoid appending the issue numbers when you don't want it.
With the following script in .git/hooks/prepare-commit-msg
when you are working in a feature branch named foo-123
, then [#123]
will be added to the third line of every commit you make.
More information in this post I wrote
#!/bin/sh
if [ x = x${2} ]; then
BRANCH_NAME=$(git symbolic-ref --short HEAD)
STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/.*-\([0-9]\)/\1/p')
if [ x != x${STORY_NUMBER} ]; then
sed -i.back "1s/^/\n\n[#$STORY_NUMBER]/" "$1"
fi
fi