- Authorization for merge requests
- Cherry-pick changes
- Merge when pipeline succeeds
- Resolve discussion comments in merge requests reviews
- Resolve conflicts
- Revert changes
- Merge requests versions
- Work In Progress merge requests
- Merge request approvals
- Ignore whitespace changes in Merge Request diff view
Merge requests allow you to exchange changes you made to source code and collaborate with other people on the same project.
There are two main ways to have a merge request flow with GitLab:
- Working with protected branches in a single repository
- Working with forks of an authoritative project
Cherry-pick any commit in the UI by simply clicking the Cherry-pick button in a merged merge requests or a commit.
When reviewing a merge request that looks ready to merge but still has one or more CI builds running, you can set it to be merged automatically when CI pipeline succeeds. This way, you don't have to wait for the pipeline to finish and remember to merge the request manually.
Keep track of the progress during a code review with resolving comments. Resolving comments prevents you from forgetting to address feedback and lets you hide discussions that are no longer relevant.
When a merge request has conflicts, GitLab may provide the option to resolve those conflicts in the GitLab UI.
GitLab implements Git's powerful feature to revert any commit with introducing a Revert button in merge requests and commit details.
Every time you push to a branch that is tied to a merge request, a new version of merge request diff is created. When you visit a merge request that contains more than one pushes, you can select and compare the versions of those merge request diffs.
To prevent merge requests from accidentally being accepted before they're completely ready, GitLab blocks the "Accept" button for merge requests that have been marked as a Work In Progress.
If you want to make sure every merge request is approved by one or more people, you can enforce this workflow by using merge request approvals. Merge request approvals allow you to set the number of necessary approvals and predefine a list of approvers that will need to approve every merge request in a project.
If you click the Hide whitespace changes button, you can see the diff without whitespace changes (if there are any). This is also working when on a specific commit page.
Tip: You can append
?w=1while on the diffs page of a merge request to ignore any whitespace changes.
Here are some tips that will help you be more efficient with merge requests in the command line.
Note: This section might move in its own document in the future.
A merge request contains all the history from a repository, plus the additional commits added to the branch associated with the merge request. Here's a few tricks to checkout a merge request locally.
Please note that you can checkout a merge request locally even if the source project is a fork (even a private fork) of the target project.
Add the following alias to your
[alias] mr = !sh -c 'git fetch $1 merge-requests/$2/head:mr-$1-$2 && git checkout mr-$1-$2' -
Now you can check out a particular merge request from any repository and any
remote. For example, to check out the merge request with ID 5 as shown in GitLab
upstream remote, do:
git mr upstream 5
This will fetch the merge request into a local
mr-upstream-5 branch and check
Locate the section for your GitLab remote in the
.git/config file. It looks
[remote "origin"] url = https://gitlab.com/gitlab-org/gitlab-ce.git fetch = +refs/heads/*:refs/remotes/origin/*
You can open the file with:
git config -e
Now add the following line to the above section:
fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
In the end, it should look like this:
[remote "origin"] url = https://gitlab.com/gitlab-org/gitlab-ce.git fetch = +refs/heads/*:refs/remotes/origin/* fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*
Now you can fetch all the merge requests:
git fetch origin ... From https://gitlab.com/gitlab-org/gitlab-ce.git * [new ref] refs/merge-requests/1/head -> origin/merge-requests/1 * [new ref] refs/merge-requests/2/head -> origin/merge-requests/2 ...
And to check out a particular merge request:
git checkout origin/merge-requests/1