How I Made Jira Show Better Commit Messages with a Simple Git Hook

2–4 minutes

It’s nice to have all your commits visible in one place, like on a Jira issue page. But let’s be honest — most of the time, those commit messages are a complete mess. They’re inconsistent, hard to read, and usually not worth opening that section for. But what if we could make them look cleaner and more readable — automatically, without any extra effort?


Let’s imagine a Jira task titled “Creating an Audit Service”, assigned to a passionate developer who’s obsessed with seeing every git commit directly on the Jira issue page. Curious and determined, he starts experimenting by following the steps below.

a. Creating a Short Feature Branch ❌

Our crazy developer starts simple.
He creates a short branch name — because shorter means faster, right? 😄

feature/cas

Then he commits:

create the project structure

And checks Jira…

OOOOPPPPSSSS. Nothing appears on the Jira page. 😬

b. Creating a Proper Feature Branch and Commit Message❌

After a deep dive into Google (and maybe a few Stack Overflow tabs), our crazy developer discovers something important:
Jira expects a specific branch naming convention, and it actually follows that pattern!

He decides to follow the standard this time.

New branch:

feature/PD-1234-creating-an-audit-service

Commit message:

create the project structure of the audit service

He eagerly refreshes the Jira page…

OOOOPPPPSSSS again. Still nothing shows up. 😩

But nobody can stop our crazy developer. He will make this work.

c. Creating a Proper Feature Branch and a Commit Message with the Branch Name Prefix ✔️

Fully confident this will be the one, our developer gives it another go.

Branch:

feature/PD-1234-creating-an-audit-service

Commit message:

feature/PD-1234-creating-an-audit-service create the project structure of the audit service

And this time…

🎉 BINGO! The commit finally appears in Jira!
Great job, crazy developer — you did it! 👏👏👏

He continues working happily for a few days and later checks Jira again…

feature-PD-1234-creating-an-audit-service create the project structure of the audit service.

feature-PD-1234-creating-an-audit add database configuration

PD-1234 create audit service class in infrastructure project

feature-PD-1234-creating-an-audit-service write unit tests for the new audit service class.

OOOPPPPSSSS. We can’t read those messages, crazy developer! What a mess, man 😅and it looks like you forgot to include the correct branch name in most of them.

But don’t worry — we believe in you! There must be a smarter way to make these commit messages look cleaner (and maybe even handsome 😎) without forcing developers to manually type the branch name every single time.


d. Creating a Proper Feature Branch with Better Commit Messages — Using a Git Hook 🚀

Our crazy developer is so close to finding the ultimate solution. He’s been experimenting non-stop, and it’s clear he just needs a little nudge.

Hang in there, man — we’ve got your back! 💪

The feature branch stays the same: feature/PD-1234-creating-an-audit-service

Now, head over to your project’s .git/hooks folder and create a new file named: prepare-commit-msg

Then, paste the following PowerShell script into it:

#!/bin/sh
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=[$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])?[0-9]+' | grep -Eo '(\w+[-])?[0-9]+' | tr "[:lower:]" "[:upper:]")]
if [[ $TICKET == "[]" || "$MESSAGE" == "$TICKET"* ]];then
exit 0;
fi

echo "$TICKET $MESSAGE" > $FILE

3. Commit the changes with a message without adding the feature branch name to it as a prefix which is add an audit controller

You see, crazy developer, you don’t need to worry about forgetting to add a long branch name to the message. And the commit messages seem more understandable.

[PD-1234] add an audit controller
[PD-1234] write unit tests for the audit controller
[PD-1234] fix the repository by replacing the query string with the correct one.