Linking an existing branch in Bitbucket to a Jira issue?

Peter Civitarese January 9, 2018

Hi,

Have been using JIRA/Confluence Cloud and Mercurial on separate server 

We have just moved to Bitbucket Cloud and linked to JIRA that is working ok.

Within an a JIRA issue, there is an option to create a "Branch" in Bitbucket. This appears to work fine for new branches moving forward and that it displays the link to the branch from within the JIRA issue.

How can you link an existing JIRA issue to an existing branch in Bitbucket so that within the JIRA issue it displays the link. Within the issue it only has the option to create a new branch, not link to an existing Branch.

Jiralink.png

Have search forums and have not come across an answer for this.

If this has been answered somewhere, can you show me the answer?

Thanks in advance

 

17 answers

1 accepted

18 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2018

JIRA uses a simple technique to link issues and branches - You need to have the issue key in the branch name.

When you create a new branch, JIRA automatically adds the issue key in the branch name. Even if you create branches outside of JIRA with the issue key in it, they will appear in JIRA. But that also means that you cannot add existing branches unless you rename them to include the issue key.

Peter Civitarese January 10, 2018

Hi Jobin,

Thanks for reply. 

"When you create a new branch, JIRA automatically adds the issue key in the branch name. Even if you create branches outside of JIRA with the issue key in it, they will appear in JIRA."

We are aware of this. Our point was more linking existing Jira Issues to an existing branch that was already created.

 

"But that also means that you cannot add existing branches unless you rename them to include the issue key...."

We tried to preform this action to rename a branch to include the Issue Key, but was unable to to do this. Is this possible? if so how?

Our last option was to close the existing branch and recreate, or create another branch and merge. messy and one we were trying to avoid.

Peter

Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2018

There is no easy renaming of branching in git. I think the proffered way is to rename the local branch, delete the remote branch and then push the renamed branch.

In Bitbucket, you can probably create a new branch, with the new name, from the existing branch and delete the existing branch.

But yeah, no easy solution I am afraid, unless you add a plugin to do it in one click ;)

Like # people like this
Peter Civitarese January 10, 2018

Ok, Could be improved as I'm sure I would not be the first to raise this type of question.

Thanks once again.....

Like # people like this
Zack Warburg September 26, 2018

I too would LOVE to see this...

Like # people like this
Saurabh Batra October 17, 2018

I would also like to see this.. being able to easily link jira and bitbucket branch is very much needed

Like # people like this
Anatol Kastyka October 23, 2018

Vote for this enhancement

Like # people like this
Becky Belechak October 26, 2018

I'd also like to see this.  It's likely that many JIRA users would already have existing repositories and branches.

Like # people like this
Rodney April 1, 2019

How is this an "Accepted Answer" and flagged as SOLVED as it only explains how it currently works and not how to take an EXISTING bitbucket branch and link it to an EXISTING Jira issue.

The answer is YOU CANNOT and you are screwed if you want to do this until Atlassian actually implements this functionality.

This is a Q&A area so where is the feature request section of Atlassian to formalize this as a feature request that can be voted on?  As this is a community area that isn't probably monitored well by Atlassian for features.

Like # people like this
Martin Kunz April 3, 2019

Fully agree with above text. Waiting for a REAL solution since one year!!!

Like # people like this
Dave Hollingshead May 20, 2019

Someone created an issue, say ABC-123, then a branch was created on a repo to solve the issue, also named ABC-123, yet on the Jira ticket, I only see Create Branch button, and I'm not seeing how to attach it to an existing branch on a certain repo.

Jira shows the repos and branches in the drop-downs, but it only lets me create a new branch even if an existing branch is exactly the same as the ticket ID.

Can someone explain this? Or how to attach the ticket to the branch?

Like R.Wolf likes this
Rodney May 20, 2019

As stated previously in this question, it is not possible. You are screwed if you create the branch first. 

That is the point and problem with this question and Atlassian is ignoring the issues brought up here in the question.  The request is for a feature to allow connecting a branch regardless of its name and when it was created to a Jira issue. 

The safest and best way to link a bitbucket branch to a Jira issue is to use the link in the issue to create the branch which requires the issue to already exist and for a developer to think that you should create branches from issues and not from Git CLI or Git tool of choice. Alternative mentioned seems to name the branch the same as the issue exactly in a specific manner, however that may violate many branching naming conventions companies and teams already have in place.  However, using that link on the issue will name it this way also thereby violating the same conventions most likely as well.

For example, if you click the create branch link you get the following:

[IssueKey]-[issue-title-with-hyphans-all-lower]

FOO-42-this-is-an-issue-title-that-is-lo

It has a max length of 40 characters total so will be truncated and IMHO looks like crap.

Like # people like this
Ranjit Kumar July 23, 2019

Hi Team, I'm exactly facing the same issue which is raised by Dave in the above, my all other stories are properly showing "1 branch" into the JIRA but there is one story ABC-123, which does not show up into the JIRA, it just say "Create Branch". Even though I've created the branch post the sprint planning meeting for all stories. Please help us, In JIRA there should be definitely a provision to link the story with the same story branch.

Carlos Alfonso August 1, 2019

It is possible to see the Bitbucket Cloud branches associated with the Feature/Story in Jira Cloud. 

You have to make sure you establish the connections between Jira and bitbucket properly (each product needs to be aware of the other). There is a sync involved. 

https://confluence.atlassian.com/bitbucket/connect-bitbucket-cloud-to-jira-software-cloud-814190686.html

 

On the Jira side you go to Admin | Jira Settings | Products | DVCS Accounts

This sets up the sync.

Like Deleted user likes this
Mouli February 18, 2020

https://jira.atlassian.com/browse/BCLOUD-17288

Vote for this issue.. This shall help..

Deleted user March 4, 2020

This is really a missing feature, Microsoft's Azure DevOps does have this.

But you could use Smart Commits to link issues?

[edit]
This might help (replace XXX-123 by your story id):

git commit --allow-empty -m "XXX-123 Linking commit to story"

 Will at least result in a linked commit... it's not much but at least you could find the work done if required

2020-03-04_16-12-57.png

[edit2]

This is a lot better, just rename the branch (https://multiplestates.wordpress.com/2015/02/05/rename-a-local-and-remote-branch-in-git/) and it will be linked to the issue.

Note that you can link multiple issues by adding multiple issue id's in the branch name. For example:
feature/xxx-123-xxx-124-multiple-issues-fixed-in-this-branch

Like # people like this
Monde April 6, 2020

Came here looking for a solution and found this one to be acceptable.

Thayne McCombs June 24, 2020

Renaming the branch really isn't an option if there is already an open pull request for the branch.

Joe Sewell July 1, 2020

Maarten's answer in [edit2] worked perfectly for me, though I already had a merged, not open, pull request.

Bill Naylor July 29, 2020

So an issue I've got is that in my organisation, we are restricted to naming our branches:

hotfix-XXX-nnn-whatever

(where XXX-nnn is the Jira tag)

So that they may be deployed on our Jenkins pipeline. This does not allow the format: XXX-nnn-whatever.

Does that mean that I'm Screwed (to quote above!)

Kevin Dietrich July 29, 2020

@[deleted] , just having the Jira ticket ID in the branch name should work fine. It doesn't have to be at the front of the branch name. At one point, I was even able to put two ticket IDs in the same branch and both Jira tickets eventually recognized the branch as belonging to both.

Note that this happens eventually. Don't expect it to show up immediately in Jira after you've pushed your changes.

Bill Naylor July 30, 2020

Right, The link has appeared now. @Kevin Dietrich Thanks for the explanation.

Nany Kuzola February 22, 2021

i completly agreed with you @Kevin Dietrich 

Simon February 24, 2021

As per Maarten Göertz 's answer , using a commit to link the branch/PR worked for me

For instance, I use something like this

git commit --allow-empty --m 'Fixes XXX-123'

where XXX-123 is our Jira ticket ID. 

Like # people like this
Frazer Kirkman April 13, 2021

@Simon that is exactly what I needed. Thank you.

Like Simon likes this
14 votes
Zhenya Kogan August 27, 2019

I came here searching for something similar. While not exactly what is being discussed, and I'm working with Github, not BitBucket, but maybe this will help someone.

I needed the ability to add existing pull requests to tickets imported into Jira. I didn't particularly care about branches and commits.

Simply renaming the Pull Request in Github to include the issue id XXX-nnn in the name triggered that PR and Branch to be linked to the Jira ticket.

Daniel Marcolesco December 2, 2019

!! HELLO READER !!

This is the correct answer.

Like # people like this
Kevin Dietrich April 3, 2020

Correction: This DOES work when tied to CodeCommit. It just takes a few minutes for Confluence to recognize the change.

Like akshat62 likes this
Tuomo Mäkelä April 21, 2020

This works in BitBucket too

6 votes
Martin Kunz November 16, 2018

Definetely would like to see this improvement/enhancement also. We have a lot of branches, which are not connected to our Jira-issues.

5 votes
Nathan Pisarski December 21, 2018

I would absolutely love this feature. This is one of those features that I thought it was so simple that it wouldn't need to be specifically asked for.

Coming from Visual Studio Team Services (the bottom of the issue tracker food-chain), I thought this functionality was a base necessity. 

I don't like the idea of polluting the git history / branch list with a bunch of JIRA-specific stuff. It just feels like abusing Git for the sake of a third party. To make an analogy, it would be like if Skype used an IRC channel with special commands like `<emoji>100</emoji>` to transmit text. IRC communication should be plain-text just like git commits / branch names should be idiomatic for Git, NOT Jira.

Ron Grosberg February 18, 2020

I have to say that I felt TFS was much better than bitbucket in a lot of ways

2 votes
Matthew Janofsky August 5, 2019

I created a feature request with Jira to add the ability to associate any BitBucket branch with any Jira ticket(s) regardless of the name of the branch.

This way you could:

  • Create a branch without having to include the ticket ID as part of the name.
  • Associate an existing branch with a new ticket.
  • Associate a branch with multiple tickets.
  • Associate multiple tickets with a single branch.

Log in and click More|Vote to add your desire to the ticket: https://jira.atlassian.com/browse/JSWCLOUD-18105

Viresh Mathad August 5, 2019

You can't view this issue

It may have been deleted or you don't have permission to view it.

Like # people like this
2 votes
Sandeep Guntupalli February 22, 2019

Would love to have this feature. Have experienced the frustration a tone of times.

1 vote
bboyairwreck June 24, 2020

+1
+ Infinity

Someone from Atlassian at least verify to us that you will put this feature in your backlog. Or give an honest technical reason why you aren't going to.

Stop suggesting to change our branch name or a title in PR. Like the dozen other ppl who explained in this thread for the last two years, this feature request is for linking AFTER the fact PR creation & merge. 

1 vote
Daniel Soares January 24, 2019
Peter Civitarese January 24, 2019

Hi Daniel,

Great to see the reference link for merging.

The link documentation is for JIRA server, we are on JIRA cloud. As we have experienced, there are some solutions for Server that can not be used on cloud and vice versa. If there is an equivalent reference for the cloud version, would be great to see it as suspect many others. I have not come across one yet.

Hint: @anyone at Atlassian listening.......

Cheers

Peter 

Daniel Soares January 28, 2019

Thank you. I will follow up with cloud customers in order to check if this solutions is applicable and I will search for a reference on Cloud.

1 vote
Daniel Soares January 24, 2019

would like to see this improvement/enhancement also. We have a lot of branches, which are not connected to our Jira-issues.

Richard Cross December 3, 2020

You can add the Jira ticket number in the Pull Request or in a commit; see answers above.

0 votes
MeijerYoung November 1, 2021

What about the ability to add issue aliases for migrations from other bug trackers?

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 17, 2021

Hi everyone,

This thread has been highly viewed over the years in Community. In an effort to try to help improve the user expectation around this topic, I want to post an updated response here.

As others have already explained in this thread, the way this particular integration feature is designed within Jira and Bitbucket, the branch name has to contain the issue key in order for that Jira issue to display it. This is simple enough to do when creating new branch from Jira's development panel. This is because Jira will automatically add that issue key to that branch name at the time of creation.

However we acknowledge this is not always as easy to manage for existing branches. There are more details about this over in Reference issues in your development work.  This is a known limitation of displaying branches.  It is only expected to display this branch at the time that branch is created.

Some users find that just creating a new pull request or commit message that contains the issue key can be one helpful way to link those development changes to a Jira issue. But clearly the original question is seeking a solution for an existing branch.

Renaming a branch could help here, however others have noted that this is not always possible, say as in situations where there are outstanding open pull requests on that branch.

For those users that would still want this ability I would recommend watching / voting on the feature request of JSWCLOUD-18105 - Allow linking a BitBucket branch with a Jira ticket without having to include the ticket key in the branch name.

In the meantime, the expectation of this feature always appears to have been in regard to the Jira issue existing first, and then creating a new branch that includes that key in its name at the time of creation.  Sorry I do not have a better way to do this today, but if this is important to you, please watch that ticket for updates to this.

Andy

Peter Civitarese April 13, 2021

Hi @Andy Heinzer , 

Thanks for the update. after 4 years since the posting, this feature would still be more than beneficial and helpful.

Mechi Fendel June 14, 2023

Add on another 2 years - still waiting for this feature - or has it been incorporated already????

Like Trung Nguyen likes this
0 votes
Mouli February 18, 2020
0 votes
Ron Grosberg January 18, 2020

We also need this very much! our product uses random seeds to do some of its tasks, which means a bug maybe present on one commit, and disappear on another commit (meaning - the bug is still there there will be on way to reproduce it) - so we need to branch from a specific commit, which means - we can't do it from JIRA UI....

0 votes
Ishan Mahajan November 7, 2019

If you want to link ABC-123 and ABC-321 just create a new branch from whichever you're working on with something like ABC-123-ABC-321-whatever then this branch will be visible linked to each of the above issues.

0 votes
Camilo Jaen November 6, 2019

Hello,

 

To link a branch with a Jira issue make sure a commit message to the branch has the Jira issue id.

This way you can (if necessary) link a single commit to multiple Jira issues.

This works regardless of the branch name or even if the branch name refers to a different Jira issue

 

i.e.: Proj-1-2001 Disables button after form submission

 

Hope it was useful

0 votes
Anton Ukhanev September 9, 2019

Oh, and I've created another issue. Let's try again.

0 votes
Anton Ukhanev September 9, 2019

If you're using Bitbucket, and only need to link one issue to the branch, here's a work-around:

 

  1. Create a new branch using the JIRA workflow, i.e. by clicking "Create branch" etc. Name of branch does not matter.
  2. Merge your existing branch into the new branch.
  3. PROFIT!!!111

Suggest an answer

Log in or Sign up to answer