Skip to content

Instantly share code, notes, and snippets.

@segovia94
Last active March 22, 2016 19:56
Show Gist options
  • Save segovia94/e2e6c42301d3b4c456a5 to your computer and use it in GitHub Desktop.
Save segovia94/e2e6c42301d3b4c456a5 to your computer and use it in GitHub Desktop.
Git hook to prepend an issue number to commit messages based on the current branch name
#!/bin/sh
# Add this file to a git repo's ./git/hooks directory
# Automatically adds branch issue ID to the beginning of every commit message.
# Branches mush end in "-(int)" like Issue-Name-1234
# Adapted from http://waiting-for-dev.github.io/blog/2014/07/19/append-issue-number-to-commit-message-automatically-with-git-hooks/
# Change the branch issue name for each project
REPONAME='SITEFARM'
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/^/$REPONAME-$STORY_NUMBER /" "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment