How can I check out a GitHub pull request with git?

GarfieldKlon picture GarfieldKlon · Dec 19, 2014 · Viewed 132.9k times · Source

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?

Answer

timbo picture timbo · Jun 2, 2015

To fetch a remote PR into your local repo,

git fetch origin pull/ID/head:BRANCHNAME

where ID is the pull request id and BRANCHNAME is the name of the new branch that you want to create. Once you have created the branch, then simply

git checkout BRANCHNAME

See the official GitHub documentation for more.