Home > Blockchain >  How to checkout a remote forked branch?
How to checkout a remote forked branch?

Time:10-29

Hello so I am working on an OS project and am trying to checkout someone else's branch.

Context:

  • I have forked the repo and have set it as my origin.
  • The original repo is set as my upstream.
  • Someone has made a draft pr, to which I want to make adjustments to (and they're aware of it as well).
  • I want to checkout his draft pr's branch
  • His draft pr is made from his forked repo to the main repo
  • I am on master locally

What I've tried:

git checkout -b [otherDevelopersUsername]:[otherDevelopersBranch] upstream/[otherDevelopersUsername]:[otherDevelopersBranch]

but I get the following error: fatal: 'upstream/[otherDevelopersUsername]:[otherDevelopersBranch]' is not a commit and a branch '[otherDevelopersUsername]:[otherDevelopersBranch]' cannot be created from it

What am I doing wrong? Thanks for the help.

edit:

git remote -vv output

origin https://github.com/[myUsernam]/[repoName] (fetch)

origin https://github.com/[myUsername]/[repoName] (push)

upstream https://github.com/[OrgName]/[repoName] (fetch)

upstream https://github.com/[OrgName]/[repoName] (push)

CodePudding user response:

If I'm understanding the question properly, the answer might be obvious.

You have two remotes:

  1. origin which is your fork of the repo.
  2. upstream which is the original repo.

And someone else made a PR, about which you state:

His draft pr is made from his forked repo to the main repo

The words "his forked repo" implies he has his own fork where his branch resides. In that case, you need a third remote pointing to his forked repo, in order to pull from it.

CodePudding user response:

If the branch exists on another forked repo, you can obtain it as follows. Add the forked repo as another remote and checkout from it:

git remote add forked https://github.com/something/something.git
git fetch forked
git checkout -b otherDevelopersBranch forked/otherDevelopersBranch

git fetch fetches any updates and new commits from the remote. The checkout command will create a local branch that tracks the remote branch otherDevelopersBranch on remote forked

  • Related