Skip to content

Instantly share code, notes, and snippets.

@raduchiriac
raduchiriac / prepare-commit-msg
Last active April 17, 2024 13:43
Hook: Prepend Jira ticket ID to the git commit message
#!/bin/bash
# Get the current branch name
current_branch=`git rev-parse --abbrev-ref HEAD`
# Search Jira ID in a pattern such a "feature/ABCD-123-my-feature"
id=$(echo $current_branch | sed -nE 's,[a-z]+/([A-Z]+-[0-9]+)-.+,\1,p')
# only prepare commit message if pattern matched and jiraId was found
if [[ ! -z $id ]]; then