Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fetch a branch on someone else's fork on GitHub? [duplicate]

People also ask

How do I pull someone else's branch in git?

If you want to check out a remote branch someone published, you first have to use git fetch . This command downloads the references from your remote repository to your local machine, including the reference to the remote branch. Now all you need to do is use git checkout <remote branch name> .

How do I fetch another remote branch?

just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

Does forking copy all branches?

The term fork (in programming) derives from an Unix system call that creates a copy of an existing process. So, unlike a branch, a fork is independent from the original repository. If the original repository is deleted, the fork remains. If you fork a repository, you get that repository and all of its branches.


$ git remote add theirusername [email protected]:theirusername/reponame.git
$ git fetch theirusername
$ git checkout -b mynamefortheirbranch theirusername/theirbranch

Note that there are multiple "correct" URIs you can use for the remote when you add it in the first step.

  • [email protected]:theirusername/reponame.git is an SSH-based URI
  • https://github.com/theirusername/reponame.git is an HTTP URI

Which one you prefer to use will depend on your situation. GitHub has a help article explaining the difference and helping you choose: Which remote URL should I use?


amalloy's suggestion didn't work for me. This did:

git remote add theirusername https://github.com/theirusername/reponame
git fetch theirusername
git checkout -b mynamefortheirbranch theirusername/theirbranch

Resources:

  • https://git-scm.com/book/ch2-5.html
  • http://crunchify.com/how-to-fork-github-repository-create-pull-request-and-merge/