Git Commit Message Hook for JIRA Issue Keys

08 Jul 2020


Credits to this StackOverflow answer:

Follow these steps to set up a global commit message hook that will extract the issue key from your branch id and prepend it to your commit messages automatically. This allows other team members to easily track down who wrote what code.


    1. Make sure you have a variant of grep installed that supports PCRE
      • On Mac you can do this using: brew install ggrep
    2. Create folder somewhere on disk for global git hooks

    3. Make a file here called commit-msg  with the following content. File is also available here.
      NOTE: Replace grep with ggrep if needed (for Mac)

    4. Make this file executable

    5. Configure git to globally use this folder as the global hook folder

Jira Issue Git Commit Prehook Example


The regexp used will match:

  • ✔️ TASK-100
  • ✔️ JAVA-1-is-the-best
  • ✔️ ROBOT-777-LETS-get-it-done-2
  • ✔️ issues/EASY-42-its-too-easy-baby

Works but be careful with:

  • ⚠️ DEJAVU-1-DEJAVU-2-maybe-dont-do-this

Will not match:

  • test-500-lowercase-wont-work
  • TEST100-nope-not-like-this

Warning: Global hooks will override local repository hooks if the projects you are using utilises them.


Posted in Programming


Leave a Reply


  1. Tyler G

    March 30, 2022 at 2:03 AM

    The list under “Will not match:” is the same as the list under ~”Will match:”
    Copy/paste error?

    • Mo Beigi

      March 31, 2022 at 11:23 PM

      Hi Tyler, yeah it was a copy and paste error. Fixed now. Thank you!

  2. Andy

    February 9, 2023 at 9:11 AM

    what if the branch is not named with Jira key and we want to check the message for the key and enforce that?

    • Mo Beigi

      February 25, 2023 at 6:11 PM

      Right now this hook is based on the branch name being set correctly first.