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?


2 answers

1 accepted

0 votes
Answer accepted

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: -David

0 votes
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 Sign up to answer
Community showcase
Published Oct 23, 2018 in Sourcetree

Tip from the team: configure your repos for hosting goodness!

Supported Platforms macOS Windows We recently introduced support for additional hosting services such as GitHub Enterprise, GitLab (Cloud, Community Edition, Enterprise Edition), and...

1,230 views 4 2
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