Andy
Andy

Reputation: 11462

git - can't make a remote tracking branch

I've read this post How do I check out a remote Git branch? a dozen times, but still nothing in there explains what I'm seeing.

I'm not trying to deliberately explore any advanced usage here - I'm trying to set up the most basic possible scenario to try out git remote branches, so I've created one repo with a master and a branch called 1.0, and cloned it to another repo. Now in the cloned repo:

$ git branch -a
* master
  remotes/origin/1.0
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

(FWIW the "master" is in green, the other lines are in red except for the "-> origin/master" which is white)

This all looks reasonable as far as I can tell. But if I try any of the following commands:

git checkout 1.0
git checkout origin/1.0
git checkout remotes/origin/1.0

I get the "detached HEAD" message, so I assume this is the wrong thing to do. Everything I've read tells me this should have created a tracking branch. (obviously I've typed 'git fetch' until I'm blue in the face as well)

If I try

git checkout -b 1.0 origin/1.0

whether or not I use --track, it seems to create a tracking branch (verified with git branch -vv) but when I try to push that tracking branch I get the error error: src refspec 1.0 matches more than one.

I understand what that message means and that it's possible to work with different branches of the same name in some odd cases, but I presume that in my case (which I repeat is to set up the simplest possible "vanilla" scenario) that isn't the right way to go about things.

Upvotes: 1

Views: 182

Answers (1)

Nogoseke
Nogoseke

Reputation: 1009

From the error message:

 error: src refspec 1.0 matches more than one.

We can assume that you may have, somehow, created more than one branch with the same name, or a tag with the same name.

Check with git branch -a that have only one branch named "1.0". And use git tag just to be sure you also don't have a tag with the same name.

If you have the option to "start clean" cloning the repository again, then using git checkout -b 1.0 origin/1.0 is the right way to create a local branch called "1.0" tracking the remote branch with the same name. And then git push origin 1.0 is what you want to use to push your changes.

Upvotes: 2

Related Questions