GitHub clone from pull request?

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.pr '!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.

Leave a Comment