How to get the issue key into the commit message automatically?

We're using the feature branch workflow with JIRA and Stash. Creating the branch from JIRA works perfectly, but when I commit on the branch I expect the commit message to be prefilled with the issue key automatically. If I commit without the key in the message the changeset won't show up Jira. But the commit message is empty, forcing me to go back to JIRA and copy and paste the key before committing - a waste of time. What am I doing wrong?

-David

2 answers

1 accepted

0 vote

The commit message is entered on the client side and there is no way to populate it from Stash, unless you do some scripting on your git client.

At best, you can prevent pushes to Stash without having a proper issue key in the commit message. Yet Another Commit Checker worked well for me to validate the issue keys.

Thanks for the tip! I have to say I do find it disappointing that ST can't figure out that the user is working on a feature and extract the issue key and prefill it in the commit message. It's not rocket science, and after all Atlassian controls every part of the solution: Jira, Stash and SourceTree;). Atlassian goes to so much trouble to connect things and save the developer time and then they ignore this low hanging fruit and force him to switch tools just to get the issue key into the commit message. Doesn't make sense. Another more general approach would be a configuration option that uses a regular expression and whatever matches that expression in the current branch name is extracted and placed in the commit message. -David

I like the regular expression check on ST. For now, ST is developed as a generic tool for any git solutions, not just for Stash, and that is probably why they do not have any hard coded rules. Any solution, should be a configurable one so that it can continue to work with other git servers like GitHub.

Hey Jobin, the solution is independent of the repo hosting solution and in fact all the information is present on the client side in a generic way. The branch name contains the Jira issue key, or more generally, some string matching a regular expression. That doesn't depend on Stash, Github, Foohub or Barhub. The rule is extract whatever matches that and put it in the commit message, as the default content. The solution that is hardcoded to a Jira issue key is also independent of the repo hosting solution, though it is of course hardcoded to the syntax of Jira issue keys. -David

Jobin, I have reworked the ST issue to specify the generic solution. Feel free to comment or vote: https://jira.atlassian.com/browse/SRCTREEWIN-3261. -David

0 vote
Timothy Chin Community Champion May 27, 2015

But the commit message is empty

You mean that after committing with a commit message and pushing to Stash, the message is not there?

No. I mean when I am making the commit in ST, the commit message is not prefilled with the issue key. I have to manually go back to Jira and copy and paste it, or manually type it. A waste of time. ST can see I am working on a branch with an issue key. To make the workflow easily to execute it could just stick that into the commit message (before I commit of course - I might want to delete it - that should be up to the user). ST already knows about pull requests in Stash, so it's no big leap to say it should know about the feature branch workflow and provide some help.

Suggest an answer

Log in or Join to answer
Community showcase
Brian Ganninger
Published Jan 23, 2018 in Sourcetree

Tip from the team: workflow and keyboard shortcuts

Supported Platforms macOS Sourcetree has a lot to offer and, like many developer tools, finding and using it all can be a challenge, especially for a new user. Everyone might not love ...

274 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot