Posted almost 10 years ago. Visible to the public.

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

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

Copy
$ 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?

Copy
$ 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:

Copy
$ 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.

Your development team has a full backlog of feature requests, chores and refactoring coupled with deadlines? We are familiar with that. With our "DevOps as a Service" offering, we support developer teams with infrastructure and operations expertise.

Owner of this card:

Avatar
Arne Hartherz
Last edit:
almost 8 years ago
by Arne Hartherz
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more