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

Updated . Posted . Visible to the public.

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

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.

Arne Hartherz
Last edit
Arne Hartherz
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2013-02-18 14:04)