Skip to content

Instantly share code, notes, and snippets.

@tcurvelo
Created September 2, 2025 17:45
Show Gist options
  • Save tcurvelo/6714efb31cc4acd1cc974a61be33bd53 to your computer and use it in GitHub Desktop.
Save tcurvelo/6714efb31cc4acd1cc974a61be33bd53 to your computer and use it in GitHub Desktop.
.git/hooks/prepare-commit-msg
#!/bin/bash
# Adds the JIRA issue ID to the beginning of the commit message
# if it is present in the branch name.
JIRA_ISSUE_REGEX='[A-Z]{2,}-[0-9]+'
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
if [[ $BRANCH_NAME =~ $JIRA_ISSUE_REGEX ]]; then
JIRA_ISSUE="${BASH_REMATCH[0]}"
COMMIT_MSG_FILE=$1
if ! grep -q "$JIRA_ISSUE" "$COMMIT_MSG_FILE"; then
sed -i.bak "1s/^/$JIRA_ISSUE: /" "$COMMIT_MSG_FILE"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment