GitHub clone from pull request?

Fresheyeball picture Fresheyeball · Feb 19, 2013 · Viewed 58.4k times · Source

I would like to clone a repository from GitHub. The problem is I don't want the main branch; I want the version in this unapproved pull request.

Is it possible for me to clone the pull request version instead of the main repository?

Answer

Chronial picture Chronial · Feb 20, 2013

The easiest way to do that is like this:

git fetch origin pull/2/head
git checkout -b pullrequest FETCH_HEAD

You will now be on a new branch that is on the state of the pull request.

You might want to set up an alias by running

git config --global alias.pro '!f() { git fetch -fu ${2:-origin} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'

Now you can checkout any PR by running git pr <pr_number>, or git pr <pr_number> <remote> if your github remote is not named origin.