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?
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 help.github.com’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 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.
I just figured it out how to do that. Let me explain what I did for everyone how has same question.
- Goto PR page on Github. The URL should looks like
.patchat the end of URL and hit Enter so the URL looks like
- 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
- Create a new local branch and checkout into that branch
- 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
- 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
- Finally you can patch it by following command:
git am --signoff < fix_empty_poster.patch
Now, you have a copy of branch for review.
- GitHub Tip: download commits as patches
- How to create and apply a patch with Git