Git pre-commit hook to validate JIRA ticket numbers in commit messages

I need help creating a git hook that checks if commit messages contain valid JIRA ticket IDs. My team wants to make sure every commit references a proper issue number before it gets pushed to our repository. I’m pretty new to writing git hooks and have never worked with JIRA integration before. Has anyone built something similar that they could share? I’m looking for a hook that would reject commits if they don’t have the right JIRA format in the message. Any working examples or code snippets would be really helpful. I’ve been searching around but most solutions I found are either too complex or don’t work with our setup.

Had this exact problem six months ago when our dev team started requiring JIRA references. I fixed it with a commit-msg hook using regex to validate ticket formats. Just drop it in your .git/hooks directory and make it executable. Mine looks for patterns like ABC-123 or PROJ-456 at the start of commit messages. Here’s the gotcha - merge commits have different message formats, so I added a condition to skip validation for those. Otherwise you’ll get false rejections. The hook only runs locally though, so everyone needs it installed or you’ll want a shared hooks directory. You’ll need to adjust the regex for your JIRA project keys, but once it’s set up it catches missing ticket references before they reach the remote repo.

We use a pre-commit hook that hits our JIRA API directly instead of just checking format patterns. Way better because it actually confirms the ticket exists and isn’t closed or invalid. I built a bash script that pulls the ticket ID from commit messages and pings JIRA’s REST endpoint. If the ticket’s bogus or throws an error, the commit gets blocked with a helpful message. Performance is fine - it’s just one API call per commit. You’ll need JIRA auth set up - we use a read-only service account. The script handles hotfix commits by checking branch patterns. Much more solid than regex validation since devs can’t accidentally reference fake tickets.

honestly, server-side hooks are the way to go - skip the client-side stuff entirely. devs always forget to install local hooks anyway. we set up a pre-receive hook that checks JIRA patterns before accepting any pushes. catches everything and nobody can bypass it locally.