550
550

Reputation: 1140

Jira: assign an existing git branch to an issue

In JIRA connected with STASH you can create a feature branch for an issue using the button 'create branch'. (That is nice to track the commits in this issue.)

If a developer started working but did not know that there is such an issue he did not click the 'create branch'.

Is there any possibility to assign an existing git branch to an issue?

Upvotes: 57

Views: 54139

Answers (8)

Suman Tiwari
Suman Tiwari

Reputation: 31

I just found a hack to attach existing branch to a jira issue. But one consideration is that the branch has a PR in github.

  1. Edit the name of PR to prefix with the jira issue id. Eg: If your PR has name like: "Fix something", then edit it to: "PROJ-11: Fix something". Here, PROJ-11 is the issue id from jira.
  2. Now you will see the PR as well as the branch appear in the jira issue after page reload.

Upvotes: 1

uwe
uwe

Reputation: 1

Just add a new commit with the Jira issue key in the commit message

Upvotes: -1

keza
keza

Reputation: 2621

The web interface option is to branch off a branch but merge back to master in the pull request.

eg:

  1. click create branch in jira
  2. set the repo, branch type and name to what you want
  3. set the branch from to be the existing branch
  4. click create
  5. when creating a pull request set the destination branch to what you want eg master

Upvotes: 1

Richard Anderssen
Richard Anderssen

Reputation: 116

If you include the JIRA-ID in the branch name, by creating out of an existing commit, all you have to do is:

git push --set-upstream origin <new-branch-name>

and the branch is attached to the JIRA ticket.

Upvotes: 0

Sid
Sid

Reputation: 14896

Update

As for january 2017 if you have an already exiting branch and you want to attach it to a Jira Issue you can do the following:

  1. Checkout to the branch you want to rename
  2. Execute the following command

    git branch -m JIRA_ISSUE_ID-Whatever

Assuming that mine Jira issue is SO-01 I can do the following:

git branch -m SO-01-Whatever

This will change the name locally, push it to remote with:

git push origin :old_name

Command Syntax

git branch (-m | -M) [<oldbranch>] <newbranch>

Related question for more info

Upvotes: 25

Randy Leberknight
Randy Leberknight

Reputation: 1453

I just tested the theory that having the Jira ID in the branch name creates an automatic link.
It does.

To see the effect, you have to push a commit. Then the branch will show up in the Jira. The branch shows up in Jira, but to get an individual commit to show up in Jira I have to refer to the Jira ID in the commit message.

Upvotes: 2

thegreenpizza
thegreenpizza

Reputation: 1451

This is no longer the case. With a common setup between bitbucket and Jira, simply including the issue ID in the commit message will create a link between the commit, and thus the branch, and the issue in Jira.

Upvotes: 19

charleso
charleso

Reputation: 1836

ex-Stash developer here.

Yes and no. Creating the branch though the UI is just a convenience. The important thing is that the name contains the JIRA key. If only one developer is working on the branch, it's fairly easy to just rename (delete + add) a branch with the appropriate name.

git checkout old-branch
git push -u origin old-branch:JIRAKEY-1234-something
git push origin :old-branch

Does that help?

Upvotes: 49

Related Questions