Skip to content

Instantly share code, notes, and snippets.

@andreyserdjuk
Last active August 16, 2016 06:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreyserdjuk/8a0c0483ee3af7ff1ea65baf2831b9bd to your computer and use it in GitHub Desktop.
Save andreyserdjuk/8a0c0483ee3af7ff1ea65baf2831b9bd to your computer and use it in GitHub Desktop.
change commit message on branch example "feature/SPRINT-123" to message: "#SPRINT-123: commit message"
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
# changes commit message on branch example "feature/SPRINT-123" to message: "#SPRINT-123: commit message"
#
# INSTALLATION:
# - copy to .git/hooks/prepare-commit-msg
# - run chmod 555 .git/hooks/prepare-commit-msg
#
NAME=$(git branch | grep '*' | grep -Po '\w+-\d+' | sed -r 's/(.*)/#\1/')
DESCRIPTION=$(git config branch."$NAME".description)
echo "$NAME"': '$(cat "$1") > "$1"
if [ -n "$DESCRIPTION" ]
then
echo "" >> "$1"
echo $DESCRIPTION >> "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment