Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 990
Hesam Avatar asked Jan 23 '15 04:01

Hesam


3 Answers

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.

So

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 help.github.com's Modifying an inactive pull request locally for more details.

like image 165
John Marshall Avatar answered Sep 25 '22 22:09

John Marshall


Another option is

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

    git remote add remote_name github.com/user/proj
    
  • 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.

like image 20
Anshul Goyal Avatar answered Sep 26 '22 22:09

Anshul Goyal


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 https://github.com/YOUR-NAME/REPO-NAME/pull/1044/files
  2. Add .patch at the end of URL and hit Enter so the URL looks like https://github.com/YOUR-NAME/REPO-NAME/pull/1044/files.patch
  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
like image 31
Hesam Avatar answered Sep 25 '22 22:09

Hesam