Read more

Git: How to check out branches that exist on multiple remotes

Arne Hartherz
February 18, 2013Software engineer at makandra GmbH

So you're using multiple remotes that offer the same branch?

$ git branch -a | grep my-branch
  remotes/something/my-branch
  remotes/origin/my-branch
Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

And when trying to check out that remote branch, it fails for you with an error like this?

$ git checkout my-branch
error: pathspec 'my-branch' did not match any file(s) known to git.

Git usually guesses the remote branch to check out, but when using more than one remote, it seems like it no longer can do that.
Even if the branch is the same on both remotes, you need to specify the branch to check out from explicitly, like that:

$ git checkout -b my-branch origin/my-branch
Branch my-branch set up to track remote branch my-branch from origin.
Switched to a new branch 'my-branch'

Maybe there is a config setting, but I didn't find one. If you know of one, let me know.

Posted by Arne Hartherz to makandra dev (2013-02-18 15:04)