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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)