Skip to content

Instantly share code, notes, and snippets.

@gelin
Last active September 18, 2024 09:27
Show Gist options
  • Save gelin/36a6eb9f0001ded501cabe29ff61a1be to your computer and use it in GitHub Desktop.
Save gelin/36a6eb9f0001ded501cabe29ff61a1be to your computer and use it in GitHub Desktop.
Git hook to put Jira issue ID from branch name to commit message
#!/bin/sh
# Hook automatically adds Jira issue ID to the commit message
# from the branch name.
# For example, if you're working in a branch `JIRA-123_something`,
# each commit message will be prepended with `JIRA-123 `.
# Copy this file as `$YOUR_GIT_REPO/.git/hooks/commit-msg` and make it executable.
TICKETS=$(git rev-parse --abbrev-ref HEAD | grep -Eo '[A-Z]+-[0-9]+' | tac)
#echo "$TICKETS"
for TICKET in $TICKETS
do
#echo $TICKET
sed -i "1s/^/$TICKET /" $1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment