Last Updated: February 25, 2016
·
450
· augenfeind

Automate your commit messages

Simply create/modify your project's .git/hooks/prepare-commit-msg - e.g. automatically prepend the [ticket number] from the beginning of your current branch's name:

#!/bin/sh
ORIG_MSG_FILE="$1"
TEMP=`mktemp /tmp/git-XXXXX`

TICKETNO=`git branch | grep '^\*' | sed 's/[_]/ /g' | cut -f 2 -d ' '`

(echo "[$TICKETNO] "; cat "$ORIG_MSG_FILE") > "$TEMP"
cat "$TEMP" > "$ORIG_MSG_FILE"