GitHub clone from pull request?

git, github, pull-request

Solution

The easiest way to do that is like this:

git fetch origin pull/<pr_number>/head:<local_branch_name>
git switch <local_branch_name>

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`.

Problem

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?

Original source

Related problems