Using Git refs to check out GitLab Merge Requests, from your local repo
When reviewing a Merge Request, it can be often more helpful to check out the codebase with the changes applied, rather than just reviewing through the interface.
If you're not wanting to just use GitLab's Web IDE, you would want to do this locally. However, that'd require you to git clone
the fork, and check out their branch, right?
Not quite! GitLab actually provides a Git ref that allows you to check out the Pull Request from within the local repo!
And in action:
$ git fetch
$ git show-ref
20a50e400fd82aa3ae9d4f97a808a38f75db2f23 refs/heads/master
20a50e400fd82aa3ae9d4f97a808a38f75db2f23 refs/remotes/origin/HEAD
20a50e400fd82aa3ae9d4f97a808a38f75db2f23 refs/remotes/origin/master
d6b3080d9b75d7a859ad0bc019c27b061e83cf23 refs/remotes/origin/merge-requests/1/head
$ git log -1 origin/merge-requests/1/head (origin/merge-requests/1/head)
commit d6b3080d9b75d7a859ad0bc019c27b061e83cf23
Author: Anna <itxad7@nottingham.ac.uk>
Date: Mon Aug 1 21:08:37 2016 +0100
Add CV template and Update Setup.sh
- Added template.tex from modernCV
- Removed bibliography and commented out picture from template
- Renamed to cv.tex
- Amended setup script to enable document type CV
Note: this is documented in GitLab's Merge Requests documentation.
Configuring per-repo using git config
If you want only the current repo you're in to attempt to pick up Merge Requests, you can run the following in the repo:
git config remote.origin.fetch '+refs/merge-requests/*:refs/remotes/origin/merge-requests/*'
Configuring globally using git config --global
If you want any repo you use to attempt to attempt to pick up Merge Requests, you can run the following in the repo:
git config --global remote.origin.fetch '+refs/merge-requests/*:refs/remotes/origin/merge-requests/*'
Configuring globally using ~/.gitconfig
The way that I've got this set up in my personal configuration is that for each repo I have, it will try and pull down any Merge Requests for the origin
remote:
[remote "origin"]
fetch = +refs/merge-requests/*:refs/remotes/origin/merge-requests/*