check out a “pull request” on Git to review/test a PR

We have a repo that I have added to my local fork as Upstream. Someone sent a PR and I want to review it. Although I’m able to review code on Github by their Diff tool but I want to have it on my local machine and test it on a real device in order to make sure it works fine (Android repo it is).

What is best way to checkout this PR?

  • What happens when I accept a pull/merge request which is behind master?
  • Git pull request branch name in teamcity
  • How to view git pull requests in a local server, in command line?
  • Code Reviewing a Pull Request With Master Merges
  • How to close a GitHub pull request with a commit message?
  • Selecting commits to send in a pull-request
  • Delete a closed pull request from GitHub
  • Merging a pull request to my fork
  • 3 Solutions collect form web for “check out a “pull request” on Git to review/test a PR”

    It’s somewhat underdocumented, but GitHub provides pull requests as branches on your Upstream repository so you don’t need to add remotes for each third party who might send you a pull request.


    git fetch Upstream pull/1044/head:pr1044-from-someone

    will make the commits in the pull request available in your local repository in a new branch, pr1044-from-someone, which you can review and merge locally as appropriate.

    See’s Modifying an inactive pull request locally for more details.

    Another option is

    • add the PR’s repository as a remote in your local copy

      git remote add remote_name
    • fetch changes from this remote

      git fetch remote_name branch_name_to_fetch
    • checkout the changes using

      git checkout remote_name/branch_name_to_fetch

    And now you can test it as per your needs on your local, you can create new branch, take a diff between branches, and so on.

    PS: IMO, this is slightly tedious compared to your current approach – if you get a lot of pull requests, adding all the remotes can be confusing and fetching all the branch history is sub-optimal, a patch is perfect.

    I just figured it out how to do that. Let me explain what I did for everyone how has same question.

    1. Goto PR page on Github. The URL should looks like
    2. Add .patch at the end of URL and hit Enter so the URL looks like
    3. Download this file or if is not downloadable create a text file, copy page and paste it into text file. Make sure the extension file is .patch (not .txt)
    4. Create a new local branch and checkout into that branch
    5. Take a look at what changes are in the patch by following command. This is just stat and doesn’t apply anything: git apply --stat fix_empty_poster.patch
    6. By following command you will see how close to trouble you are 🙂 If there is no complain be happy: git apply --check fix_empty_poster.patch
    7. Finally you can patch it by following command: git am --signoff < fix_empty_poster.patch

    Now, you have a copy of branch for review.

    More references:

    1. GitHub Tip: download commits as patches
    2. How to create and apply a patch with Git
    Git Baby is a git and github fan, let's start git clone.