Skip to content

kqf/git-commit-message-prefix-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Commit message prefix hook Build Status

A simple git hook that adds a prefix to your commit message.

Why?

Some teams require to prepend all commit messages with the corresponding Jira ticket name. So this nice-looking, self-explanatory and grammatically correct commit message:

git commit -m "Bug fix"

has to be replaced with

git commit -m "JIRA-137 | Bug fix"

This hook should do all the job automatically. The idea is to store the ticket name per branch and modify the message after one commits the changes. As an alternative approach, one can infer the ticket from the branch name, but if you like human-readable branch names, you can use this one.

Installation

The hook comes with an additional initialization script, both are installed with:

  1. Check out the code where you want (~/ was tested)
git clone https://github.com/kqf/git-commit-message-prefix-hook.git ~/.git-commit-message-prefix-hook
  1. Add the init script to your shell
echo -e "\n# Enable git-commit-message-prefix-hook\n[ -f ~/.git-commit-message-prefix-hook/hook/init.sh ] && . ~/.git-commit-message-prefix-hook/hook/init.sh" >> ~/.bash_profile
  1. Restart your shell.

How to use

By default, the hook excludes some branches such as master, so we need to create a git repository, new branch:

# Initialize the repository first
git init

# Now initialize the hook
init-git-commit-message-prefix-hook

# The branch related to the ticket
git checkout -b new-feature

Now when trying to commit with:

git commit -m "Some updates"

you will be prompted to type the prefix (Jira ticket) for your messages on this branch. All subsequent commits from the same branch will not require additional actions. Note, one branch can have one ticket associated with it, while the converse isn't true.

Releases

No releases published

Packages

No packages published

Languages