Merge Branches

There are several different ways to merge a review branch into the target branch. You can merge commits, squash and merge, rebase and merge, or merge the branches manually. You don’t need to get approvals from all reviewers before merging the review branch. If the target branch is locked, you won’t be able to merge the review branch without first contacting the project owner to unlock the target branch.

Note:

In a merge request, when you merge a review branch with the target branch, you merge all of the commits in the review branch. If you want to merge a particular commit or just some commits in the review branch, you should use the git cherry-pick command on the Git command line to apply the commit changes to the target branch. For more information, see https://git-scm.com/docs/git-cherry-pick.

To merge branches, you must be assigned either the reviewer or requester role for the merge request:

  1. Open the merge request.
  2. On the right side of the page, click Merge.
  3. In the Merge dialog box, click Merge Options, and select the merge type:
    Use this merge type ... To:

    Create a merge commit

    Merge all the review branch's commits to the target branch. The merge commits continue to show two parents.

    Squash and Merge

    Add the review branch's commit history to the target branch as a single commit.

    Rebase and Merge

    Reapply the review branch's commits and add them to the top of the target branch.

    Manual Merge

    Follow the on-screen commands to merge the branches using the Git CLI.

    Note:

    A merging message will be displayed on the Merge Request page (and on the Conversation tab), based on the merge type used to complete the merge operation. The message is shown as Merged, Rebased (shown below), or Squashed.


    Description of merge-message-rebased.png follows
    Description of the illustration merge-message-rebased.png

    The enhanced messaging distinguishes the type of operation that was used to complete the MR and helps the user understand the expected result shown in the Git commits tree. In addition, the Merged badge shows the range of commits/commit IDs.

    At the top of the dialog box, select the Remember My Choice check box to use the current option as the default setting the next time you open the Merge dialog box.

  4. If necessary, update the Merge Summary and Merge Description.
    The fields aren’t available if you select Rebase and Merge or Manual Merge.
  5. To delete the review branch after the commits are merged with the target branch, select Delete Branch.
  6. If there are any linked issues, deselect the check boxes for the issues that you don’t want to mark as resolved after the commits are merged with the target branch. By default, the check boxes for all linked issues are selected.
  7. Submit the dialog box.
After the review branch has been merged, the merge request will be closed automatically. No other action is allowed.
If you didn’t select the Delete branch check box when you merged the review branch, note that the review branch wasn’t removed from the Git repository. You can continue to make commits to the branch and create another merge request to review the new source code.