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?
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.
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.
https://github.com/YOUR-NAME/REPO-NAME/pull/1044/files
.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
.patch
(not .txt
)git apply --stat fix_empty_poster.patch
git apply --check fix_empty_poster.patch
git am --signoff < fix_empty_poster.patch
Now, you have a copy of branch for review.
More references:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With