I'd like to check out a previously created pull request (created via GitHub web interface). I searched and found different places where a refs/pull or refs/pull/pr
But when I add fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to the git config file and do a git fetch
What I'm doing wrong? Should GitHub create automatically the pull/xyz stuff, or do I have to configure something?
To fetch a remote PR into your local repo,
where
ID
is the pull request id andBRANCHNAME
is the name of the new branch that you want to create. Once you have created the branch, then simplySee the official GitHub documentation for more.
I accidentally ended up writing almost the same as provided by git-extras. So if you prefer a single custom command instead of installing a bunch of other extra commands, just place this
git-pr
file somewhere in your$PATH
and then you can just write:I prefer to fetch and checkout without creating a local branch and to be in HEAD detached state. It allows me quickly to check the pull request without polluting my local machine with unnecessary local branches.
git fetch upstream pull/ID/head && git checkout FETCH_HEAD
where
ID
is a pull request ID andupstream
where is original pull request has been created (it could beorigin
, for example).I hope it helps.
The problem with some of options above, is that if someone pushes more commits to the PR after opening the PR, they won't give you the most updated version. For me what worked best is - go to the PR, and press 'Commits', scroll to the bottom to see the most recent commit hash and then simply use git checkout, i.e.
git checkout <commit number>
in the above example
git checkout 0ba1a50
Referencing Steven Penny's answer, it's best to create a test branch and test the PR. So here's what you would do.
git checkout -b test
git pull origin pull/939/head:test
Now, you can safely test the changes on this local test branch (in this case, named test) and once you're satisfied, can merge it as usual from GitHub.
You can use
git config
command to write a new rule to.git/config
to fetch pull requests from the repository:And then just: