Skip to content

pedrocatre/git-hook-story-ticket-number

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

git-hook-story-ticket-number

git hook to add branch code to commit message

Automatically adds story code from the branch name and branch description to every commit message.

Example: [API-123] my commit

Why is this useful?

I'm working on projects where the team follows a branch naming convention that includes the ticket code/number of the task the branch refers to. We have a JIRA and bitbucket configuration that links the commits and the tasks as long as we include the task code/number in the commit.

Main advantage would be that it is easy to see what tasks/stories are being released and what is their state and if there is any prerequisite before release.

Having this automated is important so we don't waste time filling out this code on every commit message and so we don't get it wrong when switching between branches we are working on.

Branch naming convention

One issue code

Since the story code is taken from the branch name we assume the following convention for the branch naming:

{type_of_branch}/{story_code}/{name_of_story}

for example from branch name:

feature/API-34193/edit-refund-role

we get:

[API-34193] my commit message

If you are in the develop branch and you commit the commit message will look like:

[develop] my commit message

Two issue codes

If subtasks are used, the naming convention for branch name can be:

{type_of_branch}/{story_code}/{subtask_code}/{name_of_subtask}

for example from branch name:

subtask/API-34193/API-34194/edit-refund-role-part-one

we get:

[API-34193] [API-34194] my commit message

No issue codes

If the branch name doesn't contain any code, the commit message won't be modified.

Dependencies

This hook needs nodejs to run.

Installing the hook locally

You need to have nodejs installed.

  • Add the prepare-commit-msg file to the .git/hooks subdirectory of your project.
  • Make the hook file executable: chmod +x .git/hooks/prepare-commit-msg

Installing the hook globally (recommended)

You can install this hook globally by using a git template instead of setting it up for every repository.

mkdir -p ~/.git-templates/hooks git config --global init.templatedir '~/.git-templates'

Copy the hook into

~/.git-templates/hooks

Set permissions on file

chmod a+x ~/.git-templates/hooks/prepare-commit-msg

NOTE: you will need to reinitialised existing Git repositories. To achieve this go to the repository and run:

git init

The repository is reinitialised and nothing breaks.

About

git hook to add task branch code to commit message

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published