Skip to content

Instantly share code, notes, and snippets.

@dmitryn
Last active October 25, 2017 14:31
Show Gist options
  • Select an option

  • Save dmitryn/5005684 to your computer and use it in GitHub Desktop.

Select an option

Save dmitryn/5005684 to your computer and use it in GitHub Desktop.
Git commit-msg hook which adds github issue number to commit message baed on current branch name.
#!/bin/sh
# Adds github issue number to commit message based on current branch name.
# Example: current branch '308-context-help', commit message 'fix bug',
# final commit message will be '#308 fix bug'
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment