teobais
teobais

Reputation: 2966

How to checkout (on a forked repo) a Pull Request coming from the main repo?

Supposedly I find project A really cool and I fork it on my profile. Then I have the forked version of project A; let's name it project B.

A user opens a pull request on project A.
However, since I already have project B (which is the fork of project A), I would like to checkout the pull request that was opened on project A, on my project B.

That would come more handy, considering that project A differs now from project B.

Is there any solution on that?
Whatever I found around the net till now is only about checking out a pull request opened on project A.

Upvotes: 0

Views: 246

Answers (2)

teobais
teobais

Reputation: 2966

What @cpanato mentioned is indeed correct, but only the first step , because the question is about being able to checkout a pull request and not a branch.

The following line needs to be added to your .git/config file (upstream section):

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

Then you are ready to fetch the upstream: git fetch upstream
And then you can checkout a specific pull request like below:

git checkout origin/pr/11

For more details, you can always consult a short article that I've written.

Upvotes: 1

cpanato
cpanato

Reputation: 429

You will need to set the project A in your remote and the fetch that and then check out the branch that the user open the PR

let's say your git remote -v is:

origin https://github.com/toubou/projectA.git (fetch)
origin https://github.com/toubou/projectA.git (push)

you will need to add another entry to map the original project A

$ git remote add upstream https://github.com/ORGINALREPO/projectA.git

then your git remote will be like:

origin https://github.com/toubou/projectA.git (fetch)
origin https://github.com/toubou/projectA.git (push)
upstream https://github.com/ORGINALREPO/projectA.git (fetch)
upstream https://github.com/ORGINALREPO/projectA.git (push)

Now you do:

$ git fetch upstream

and then check out the branch the user open the pr:

$ git checkout branch_name

Upvotes: 1

Related Questions