Last active
October 19, 2023 14:24
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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