This post shows how to checkout github pull requests (PRs) locally to test before merging.
Note: This post significantly qouted from this gist by Bert Belder, a.k.a @piscisaureus and it's comments, just for documentation (JFD) purpose.
Method 1
Step 1: Checking out PRs
Locate the section for your github remote in the .git/config
file. It looks like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:KINGSABRI/MyRepository.git
Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:KINGSABRI/MyRepository.git
fetch = +refs/pull/*/head:refs/remotes/origin/pr/*
Step 2: Fetch All PRs
$ git fetch origin
From github.com:KINGSABRI/MyRepository
* [new ref] refs/pull/1000/head -> origin/pr/1000
* [new ref] refs/pull/1002/head -> origin/pr/1002
* [new ref] refs/pull/1004/head -> origin/pr/1004
* [new ref] refs/pull/1009/head -> origin/pr/1009
...
Step 3: Check out a Particular pull request
$ git checkout pr/1000
Branch pr/999 set up to track remote branch pr/999 from origin.
Switched to a new branch 'pr/999'
Method 2
By adding the other user's repository url as a remote repository
git remote add other_user other_user_repo_url
git fetch other_user
git checkout -b other_user_branch other_user/branch
Method 3
For featching only one pull request
git fetch origin pull/7324/head:pr-7324
origin
points to the remote server.pull/7324/head
is the remote pull request.pr-7324
is the local pull-request branch.