Automatically add Jira issue ID to commit messages based on the current Git branch name.
Install in local repo:
cp commit-msg path/to/repo/.git/hooks/commit-msg
chmod +x path/to/repo/.git/hooks/commit-msg
Global install:
mkdir -p ~/.git-template/hooks
cp commit-msg ~/.git-template/hooks/commit-msg
chmod +x ~/.git-template/hooks/commit-msg
git config --global init.templatedir ~/.git-template
When installing globally it will only work for repos that are cloned/inited after the install.
The workflow consists of checking out a branch with the Jira issue ID prefixed to the branch name.
The recognized Jira issue ID format is [A-Z]+-[0-1]+
.
When creating a commit in such a branch the commit hook will atomically prefix the commit message with the Jira issue ID so that the commit can be tied to its issue in Jira.
E.g.:
git checkout -b PROJ-1-branch-description
git commit -m "Some info about this commit"