Skip to content

Instantly share code, notes, and snippets.

@Thann
Last active December 23, 2015 00:42
Show Gist options
  • Save Thann/04544bbff94254a7b543 to your computer and use it in GitHub Desktop.
Save Thann/04544bbff94254a7b543 to your computer and use it in GitHub Desktop.
GIT: Prepend the Jira ticket from the branch name to the commit message
#!/bin/sh
#
# Prepend the Jira ticket from the branch name to the commit message
# Do nothing when amending or fixing
if [ -n "$2" ]; then exit 0; fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
TICKET_NAME=$(echo $BRANCH_NAME | grep -Eo "^\w{2}[-_][0-9]+" | awk '{print toupper($0)}')
if [ -n "$TICKET_NAME" ]; then
sed -i.bak -e "1s/^/$TICKET_NAME - /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment