JetBrains Space Help

Merge Requests

Before merging a branch you've been working on into the base branch (main, master), you can create a merge request inviting your teammates to examine and approve the changes.

Merge request is a special kind of code review that lets you:

  • Compare the two branches.

  • Easily spot conflicts if any.

  • Merge your branch right from the review page (rebase and squash as well).

Create a merge request

  1. Follow the graph on the commits list to locate the branch you want to merge.

  2. Select the top commit of the branch.

  3. On the right pane, click New merge request:

    mergeRequest.png

    A dialog with merge request options will pop up.

  4. Select the target branch (the branch you want to merge into):

    selectTargetBranch.png
  5. Add description (optional):

    addDescriptionMergeRequest.png
    • Click Add description.

    • Type you description into the text field or click Copy text from commit messages.

    • Description based on commit messages can be edited using Markdown.

    You can also edit the title of this merge request.

  6. Assign reviewers:

    addReviewerMergeRequest.png

    If your merge request requires approval from certain people as part of Quality gates protection, Space will suggest them for reviewers. Please add these suggested reviewers and get their approval, otherwise you won't be able to merge your changes:

    addQGReviewersMergeRequest.png
  7. Click Create merge request.

    A merge request code review will be created:

    mergeRequestReviewCreated.png

    If your merge request includes changes in files owned by an assigned reviewer, you can indicate whether you want that reviewer to examine all changed files or only the ones they own:

    mergeRequestAllOrOwnedFiles.png

    Your selection determines what the reviewer will initially see in the Changes tab: either all changed files or only the ones where they are the code owner.

    Code ownership is based on the CODEOWNERS file which can be configured for your repository.

  8. Now you can:

    • Compare your branch with the target branch.

    • Check your status.

    • Reply to reviewer's feedback or proceed to merge when your request is approved.

Review a merge request

If someone asks you to review and approve their merge request, follow the instructions outlined in Review Changes Made by Others.

In addition, you may need to:

  • Compare the branches before approving the request.

  • Choose whether you want to review all files included in the merge request or only those you own.

    Code ownership is based on the CODEOWNERS file which can be configured for your repository.

    mergeRequestAllOrOwnedFilesReviewer.png
    • All files — With this option selected, if you Approve changes, your approval will be reset when additional changes are introduced to any files.

      If you Approve and finalize, your status will stay final, it won't be reset with new commits.

    • Owned files — With this option selected, if you Approve changes, your approval will be reset only if changes added afterwords affect the files you own. Changes made to any files you don't own will not reset your status.

      If you Approve and finalize, your status will stay final irrelevant of the files affected afterwords.

Compare branches and commits

The default diff view of the Merge request code review shows the difference between the head of the source branch (the branch being reviewed) and the head of the target branch. For this diff view, all commits should be selected in the left pane:

mergeRequestDefaultDiff.png

If the system detects any conflicts that cannot be resolved automatically, a warning will be shown:

conflictsDetected.png

Files with conflicts will be labeled with a red exclamation mark. A conflicting branch cannot be merged until all conflicts are manually fixed.

You can also compare the source branch commits with their parent commit. To do so, in the left panel, select only the commit you want to compare.

The branches can be also compared from the commit list:

  1. Follow the graph on the commits list to locate the branch that should be merged, or go to Branches and open the branch.

  2. Select the top commit of the branch.

  3. On the right pane, click Compare to default:

    clickCompareToDefault.png

    A diff will be displayed. It shows the differences between the head of the selected branch and the head of the default branch.

  4. Review the changes and check for conflicts.

Code analysis

If your project is integrated with an external code analysis tool, all changes within a merge request will be inspected, a summary will be displayed on the merge request page and code problems will be highlighted in the merge request diff.

The code analysis summary is shown in the right-hand Details panel:

mergeRequestCodeAnalysisSummary.png

Erroneous code fragments are underlined with a red squiggly line in the merge request diff. Click on the line to see the error description:

mergeRequestCodeAnalysisDiff.png

Check your status

In a code review, including merge requests, participants take turns to keep the process clear and orderly. The status indicator under your name in the right-hand panel will tell you whether you should wait or take action.

authorStatusWaiting.png

Gray color indicates that no action is required, wait for the reviewer to finish their turn.

authorStatusRevising.png

Orange color indicates that it's your turn, and you are expected to take some action such as:

  • Reply to comments posted by the reviewer.

  • Commit some additional changes or fixes.

Once you're finished, click the suggested action in the top right corner to change your status and pass the turn to the reviewer.

authorStatusEnd.png

A blank status under your name indicates that the review is complete and your branch can be merged. Click the Merge button to merge your branch and close the review.

Reviewer's approval

When reviewers accept your changes, you are notified in Chats. Their resolution will be also posted on the review page under the Timeline tab, and indicated on their user icons (they will be encircled in green):

mergeRequestApproved.png

Merging options

As soon as the reviewers accept your request, you can merge your branch into the default branch right from the Space interface.

You have the following options:

  • Merge — merge your branch back into the default branch with a merge commit.

  • Rebase — move your branch to the tip of the default branch without a merge commit.

  • Rebase and squash — combine all commits from your branch into a single commit and move it to the tip of the default branch.

You can also choose whether to keep your branch after the merge or delete it.

Merge a branch

This option lets you add all commits from your feature branch to the default branch with a merge commit.

  1. Open the review page and click Merge:

  2. Choose Merge.

    mergeOptionsMerge.png
  3. If you want your branch deleted after the merge, select the corresponding checkbox.

  4. Click Merge.

    Your branch will be merged into the default branch and the history of all commits will stay intact.

    mergeBeforeAfter.png

After you've merged the branch, you can close the review.

Rebase and merge a branch

This option lets you rebase your feature branch before it is merged into the default branch. All commits of your feature branch will be added to the tip of the default branch without a merge commit.

You can also choose to delete your branch after the merge.

  1. Open the review page and click Merge:

  2. Choose Rebase:

    mergeOptionsRebase.png
  3. If you want your branch deleted after the merge, select the corresponding checkbox.

  4. Click Merge.

    Your branch will be rebased and merged into the default branch without a merge commit. The commit history will be rewritten resulting in a linear commit graph.

    rebaseBeforeAfter.png

After you've merged the branch, you can close the review.

Squash, rebase, and merge a branch

This option lets you squash your feature branch into a single commit and then rebase it before it is merged into the default branch. All commits of your feature branch will be combined into one and then added to the tip of the default branch without a merge commit.

You can also choose to delete your branch after the merge.

  1. Open the review page and click Merge:

  2. Choose Rebase and squash:

    mergeOptionsSquashRebase.png
  3. Enter your commit message for the squashed commit.

  4. If you want your branch deleted after the merge, select the corresponding checkbox.

  5. Click Merge.

    Your branch will be squashed into a single commit, rebased and merged into the default branch without applying a merge commit. The commit history will be rewritten resulting in a linear commit graph and fewer commits.

    squashBeforeAfter.png

After you've merged the branch, you can close the review.

Last modified: 02 February 2024