Creating a branch from issue in GitLab

31,435

Solution 1

If you create a branch with the name <issue-number>-issue-description and push that branch to gitlab, it will automatically be linked to that issue. For instance, if you have an issue with id 654 and you create a branch with name 654-some-feature and push it to gitlab, it will be linked to issue 654.

Gitlab will even ask you if you want to create a merge request and will automatically add Closes #654 to the merge request description which will close issue 654 when the merge request is accepted.

Also if you go to a given issue page on gitlab, you should see a New Branch button which will automatically create a branch with a name of the form <issue-number>-issue-description.

Solution 2

On the Issue screen, you see a green button labeled "Create merge request", with a down-arrow to its right.

That's not a button, that's a drop down list of buttons.

  • Click on the down arrow
  • Choose "Create branch"
  • Click on "Create branch"
  • A branch is created from the issue number, plus the title of the branch
    • For example, my issue #2, with title "Test repoSearch with no repos" will have a branch called:
    • 2-test-reposearch-with-no-repos
    • Notice that it changes case to all-lower-case
Share:
31,435
JonasN89
Author by

JonasN89

Updated on July 09, 2022

Comments

  • JonasN89
    JonasN89 almost 2 years

    I've just started using GitLab, and have created a set of issues, in order to keep an overview of what needs to be done for my application. I was wondering if it was possible to create a branch from these issues, such that the branch and issues are linked, similar as in jira and Stash from atlassian?

  • JonasN89
    JonasN89 about 7 years
    I was hoping to see a New Branch button, but either its not there or I can't find it. Do you know where it is placed?
  • JonasN89
    JonasN89 about 7 years
    never mind found the create new branch. It seems like Gitlab created a branch for me for the first issue, without realizing it myself.
  • florisla
    florisla over 6 years
    Regarding the missing Create Branch button, see @Robert Echlin's answer.
  • Zoltán
    Zoltán about 6 years
    @JonasN89 you should consider changing the accepted answer to Robert Echlin's answer because that exactly answers your question.
  • molerat
    molerat almost 6 years
    That button is not displayed for me. Does it have to do with my branch structure (Git Flow) or because it is a fork of a different project?
  • Roger Campanera
    Roger Campanera over 5 years
    Is it posible for GitLab to recognise other name format? For instance, create a branch called feature/2 by default instead of 2-the-title. And, would they be linked by GitLab? That would be a must feature IMHO.
  • Michael Kargl
    Michael Kargl almost 5 years
    An observation: the "Create Pull Request for Issue" Button is only visible once an Issue is Non-Confidential.
  • ThinkDigital
    ThinkDigital over 4 years
    @molerat I'm having the issue where it's not showing for me either in the current project. In one project, I have 2 buttons. Show Activity and Create Merge Request. In the other, I only have Show Activity
  • fudo
    fudo almost 4 years
    same here, on some issues the button is displayed while not in others; cannot understand which criteria gitlab uses to show it or not
  • Hendrik Pilz
    Hendrik Pilz about 3 years
    The repository must not be empty and the 'repository' feature should be enabled in the project settings (Settings > General > Visibility, project features, permissions). Tested on Gitlab 13.8.7 / Docker.
  • Jubilsoft-Scott
    Jubilsoft-Scott over 2 years
    See this issue regarding the Merge Request button not displaying on the Issue screen.
  • Timothy L.J. Stewart
    Timothy L.J. Stewart over 2 years
    @RogerCampanera it seems the only option for Gitlab is feature/2-<some-branch> then when you do a merge request add #2 in the comment box and it will link then, you could just do a MR right from the start to link it. From what I can tell on Gitbhub you can link pull-request to feature/2-<some-branch> but doesn't have the autolinking of 2-<some-branch> like GitLab