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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)