Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to checkout a remote forked branch?

Tags:

git

github

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)

like image 272
DevReacc Avatar asked Oct 19 '25 17:10

DevReacc


2 Answers

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

like image 86
David Sugar Avatar answered Oct 22 '25 07:10

David Sugar


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.

like image 27
TTT Avatar answered Oct 22 '25 07:10

TTT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!