Skip to content

Instantly share code, notes, and snippets.

@denniseilander
Last active October 19, 2023 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denniseilander/38dce9ec1f9318a79bfc55d5410e69d3 to your computer and use it in GitHub Desktop.
Save denniseilander/38dce9ec1f9318a79bfc55d5410e69d3 to your computer and use it in GitHub Desktop.
Git commit hook to always append the ticket number of the current branch when making a commit.
#!/bin/bash
# Get the current branch name
branch=$(git symbolic-ref --short HEAD)
# Extract the ticket number from the branch name e.g. feature/AB-123
# This regex assumes that the ticket number is always preceded by a '/'
ticket_number=$(echo $branch | sed -n 's/.*\/\([A-Z]*-[0-9]*\)/\1/p')
# If a ticket number was found, append it to the commit message
if [[ ! -z $ticket_number ]]; then
echo -e "\n$ticket_number" >> $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment