I‘m a big believer in code reviews. When I’m trying to review a PR on GitHub, I almost always want to check out the code locally on my computer, so I can open it up in an IDE. This is easy to do, but unfortunately, it’s not commonly documented. You can always check the branch behind the PR out by name, but I find it easier to use the PR number. It’s also easier to do this as part of a larger script. Instructions to set this up are below.
Open the .git/config
file from the root of the repo in a text editor. Find the section that looks like this (note that the value of url
will be different for you):
[remote "origin"]
url = git@github.com:surya-soft/Kedwig.git
fetch = +refs/heads/*:refs/remotes/origin/*
Add this line (this will not change, regardless of what your url
is):
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to the end of it, to make it look like so:
[remote "origin"]
url = git@github.com:surya-soft/Kedwig.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Save the file.
Run git fetch
. You will now have refs to each PR by number. To check out PR 1, you can run git checkout origin/pr/1
. This will check out the PR in a detached head state. Replace 1
with the number of the PR you want to reivew, and you’re all set!