Yes, this is a good idea and fairly standard (but not universal) practice.

The specific software engineering goal you are achieving with this is requirements traceability. The idea is you want to be able to trace a requirement through the entire software process:

  1. Business requirements
  2. Functional requirements
  3. Technical requirements
  4. Code artifacts
  5. QA feedback
  6. Development fixes

By using ticket or requirement numbers (e.g. Jira story IDs) in commit messages and any correspondence, you are working toward that software engineering goal.

If I come back a year later and see the commit message, I can look up that number in another system to get the full background behind the requirement or ticket, including anything that occurred after the commit.

Answer from user22815 on Stack Exchange
🌐
DEV Community
dev.to › visuellverstehen › new-git-guidelines-we-have-switched-to-conventional-commits-1p0c › comments
[Discussion] New git guidelines: We have switched to Conventional Commits — DEV Community
October 22, 2022 - In my opinion Ticket numbers are superfluous really. They're only useful if you endeavour to utilise the same Ticketing system for the life of the product (which realistically isn't always viable). More importantly I believe you should write useful and meaningful commit messages without relying on the ticket as reference.
🌐
GitHub
github.com › integrations › jira › issues › 354
Identifying JIRA tickets in conventional-commits · Issue #354 · atlassian/github-for-jira
May 5, 2020 - stay tunedWe have a ticket in our backlog and will update contributor when work commencesWe have a ticket in our backlog and will update contributor when work commences ... We use https://www.conventionalcommits.org/en/v1.0.0/ in our team. ... We see that if we do re #[JIRA-ID] in the commit, then ...
Author   gazal-k
Discussions

version control - Is there any downside to commit messages containing the ticket number - Software Engineering Stack Exchange
You might use a different convention for commits you know you're going to rebase/squash - they're only need to be useful for a short time; or you might use a different convention for merge commits; but if you want to answer a question like "which tickets have been worked on since the last tag", ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
January 22, 2016
Customize commitlint with conventional commit + JIRA Ticket - Stack Overflow
I am using commit lint and I want to use conventional commits but i want to include a Jira Ticket. Example TEST-23: fix: my body More on stackoverflow.com
🌐 stackoverflow.com
githooks - Append ticket number using git commit hooks? - Stack Overflow
So my branch is named after bugtracker ticket number, something like "issue-1234", and we have a convention to always write down ticket number in commit message. I'm wondering if it's pos... More on stackoverflow.com
🌐 stackoverflow.com
git - Including issue code in the commit message header according to Conventional Commits - Stack Overflow
I am following the Conventional Commits guidelines v1.0.0 for my project and I have a question about including the issue code in the commit message header. Let's say I have an issue with code "... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › Skywalker427 › jira-conventional-commit
GitHub - Skywalker427/jira-conventional-commit: Generate conventional commits with jira ticket information · GitHub
This is useful for teams that use JIRA or other ticketing systems. The script will validate the branch name to ensure it matches the expected pattern. If the branch name is valid, the ticket number will be added to the commit message.
Author   Skywalker427
🌐
Jbs
jbs.dev › resources › resource-center › blog › creating-detailed-commit-history-conventional-commits
Creating A Detailed Commit History With Conventional Commits
They allow us to keep track of changes and communicate the status of the repository to other team members. A popular approach is to add ticket numbers or other identifiers to the commit message. That will help us eventually track down what is happening in a repository but that kind of information is really meant for your project and issue tracking integration.
🌐
Conventional Commits
conventionalcommits.org › en › v1.0.0
Conventional Commits
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of.
🌐
DEV Community
dev.to › danywalls › how-to-improve-your-git-commit-messages-using-conventional-commits-49f5
How To Improve Your Git Commit Messages Using Conventional Commits - DEV Community
August 4, 2023 - When writing a commit following the conventional commits guide, it has the following structure. type: scope: description or message optional body optional footer · The type expresses the intention, and the scope indicates the affected area. For example: fix: (icon-library) Change the input prop of the state icon to match the identifier. Refs: #jira-ticket-number or pbi
🌐
GitHub
gist.github.com › qoomon › 5dfcdf8eec66a051ecd85625518cfd13
Conventional Commits Cheatsheet · GitHub
If your next release contains commit with... ... feat!: remove ticket list endpoint refers to JIRA-1337 BREAKING CHANGE: ticket endpoints no longer supports list all entities.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 76765811 › customize-commitlint-with-conventional-commit-jira-ticket
Customize commitlint with conventional commit + JIRA Ticket - Stack Overflow
import type { UserConfig } from '@commitlint/types'; const Configuration: UserConfig = { extends: ['@commitlint/config-conventional'], rules: { 'type-empty': [0], 'subject-empty': [0], 'task-type-pattern': [2, 'always'] }, plugins: [ { rules: { 'task-type-pattern': ({ header }) => { const regex = /^TEST-\d+: (feat|fix|perf|style|docs|test|refactor|build|ci|chore|revert|wip|workflow): .+/; if (!header || !regex.test(header)) { return [ false, 'Commit message must be in the format: <TASK-NUMBER>: <TYPE>: <MESSAGE> (e.g., TEST-23: fix: my body)', ]; } return [true]; }, }, }, ], }; export default Configuration;
🌐
Lhowsam
lhowsam.com › blog › conventional-commits-a-better-way-to-commit
Conventional commits, a better way to commit | lhowsam.com
While I like conventional commits, I don't use it typically on every project. I've found it's quite common to just follow the convention of using the Jira ticket number as a template for a commit message such as:
🌐
Daily Dev Tips
daily-dev-tips.com › posts › git-basics-conventional-commits
Git basics: Conventional commits - Daily Dev Tips
November 20, 2021 - optional body: A more detailed description of the commit. This is optional but handy for bigger commits · optional footer: Can state breaking changes and reference issues by ticket number
🌐
Medium
medium.com › @BradleyOThompson › conventional-commits-ffad83dfe561
Improve Your Git Commits By Using Conventional Commits | by Bradley Thompson | Medium
May 18, 2024 - Improve Your Git Commits By Using Conventional Commits When collaborating on projects, clear and consistent commit messages are essential. Conventional Commits establishes a consistent structure for …
🌐
DEV Community
dev.to › luchfilip › making-git-commit-messages-useful-with-jira-jenkins-and-scopes-5759
Making git commit messages useful with Jira, Jenkins and scopes - DEV Community
March 1, 2019 - TIP: I'm a CLI guy, but if you ... → Display column guide in commit message at character. Ticket ID contains the ticket number this commit is related to....
🌐
Medium
medium.com › @sagormahtab › mastering-commit-messages-the-ultimate-guide-to-conventional-commits-96f038da6bdf
Mastering Commit Messages: The Ultimate Guide to Conventional Commits | by Mahtab Hossain | Medium
September 4, 2023 - Additionally, the reference to the issue number helps in issue tracking and management. Here are some additional takeaways to boost up your game: Use git commit -m “summary” -m “description” for better clarity. Keep the summary under 50 characters and the description under 72 characters. Write commit messages in imperative tense, e.g., “Add feature” instead of “Added feature.” · Include Conventional commit type prefixes. Reference JIRA ticket ...
🌐
DEV Community
dev.to › visuellverstehen › new-git-guidelines-we-have-switched-to-conventional-commits-1p0c
New git guidelines: We have switched to Conventional Commits - DEV Community
October 24, 2022 - In my opinion Ticket numbers are superfluous really. They're only useful if you endeavour to utilise the same Ticketing system for the life of the product (which realistically isn't always viable). More importantly I believe you should write useful and meaningful commit messages without relying on the ticket as reference.
Top answer
1 of 7
29

You missed a hook. The one you want is commit-msg:

This hook is invoked by git commit, and can be bypassed with --no-verify option. It takes a single parameter, the name of the file that holds the proposed commit log message. Exiting with non-zero status causes the git commit to abort.

So for example:

#!/bin/sh

ticket=$(git symbolic-ref HEAD | awk -F- '/^issue-/ {print $2}')
if [ -n "$ticket" ]; then
    echo "ticket #$ticket" >> $1
fi

That's a very naive parsing of your branch name, and it's simply appended to the commit message on its own line. Modify it if that's not good enough for you.

Of course, I'd actually recommend doing this in prepare-commit-msg, and committing with git commit (without -m). It's very, very rare that you can actually write sufficient information in a single-line commit message. Further, that will let you see the message before the commit is made, in case your hook doesn't do quite what you want.

2 of 7
11

You can as well use prepare-commit-msg hook, which accepts more parameters than commit-msg. Then you can check if the message is coming from a file, a template, etc to avoid appending the issue numbers when you don't want it.

With the following script in .git/hooks/prepare-commit-msg when you are working in a feature branch named foo-123, then [#123] will be added to the third line of every commit you make.

More information in this post I wrote

#!/bin/sh
 
if [ x = x${2} ]; then
  BRANCH_NAME=$(git symbolic-ref --short HEAD)
  STORY_NUMBER=$(echo $BRANCH_NAME | sed -n 's/.*-\([0-9]\)/\1/p')
  if [ x != x${STORY_NUMBER} ]; then
    sed -i.back "1s/^/\n\n[#$STORY_NUMBER]/" "$1"
  fi
fi
🌐
Medium
proandroiddev.com › code-commit-guidelines-using-conventional-commits-379321ce3785
Code Commit Guidelines using Conventional Commits | by Pragnesh Ghoda | ProAndroidDev
September 11, 2023 - Each PR should contain ticket details and the title of the PR. It should also contain the type of ticket so team members can check if it was a feature/enhancement or bug fix. In general, the commit message should be structured as the following pattern:
🌐
GitHub
github.com › ytanikin › PRConventionalCommits
GitHub - ytanikin/PRConventionalCommits · GitHub
Automatic Labeling: Labels the PR based on the task type mentioned in the title. Can be disabled. Ticket Number Validation: Optionally checks the provided ticket number format using regular ...
Starred by 6 users
Forked by 2 users
Languages   JavaScript
🌐
Latenode
community.latenode.com › other questions › jira
How to configure commitlint for conventional commits with JIRA ticket integration - Jira - Latenode Official Community
June 10, 2025 - I’m working on a project where we need to enforce commit message standards using commitlint. We want to follow the conventional commit format but also need to include JIRA ticket numbers in our commit messages. For example, I want my commits to look like this: PROJ-456: feat: add new user ...