1

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.

Community
  • 1
  • 1
Andy
  • 10,412
  • 13
  • 70
  • 95
  • What command are you using to push? – Nogoseke Dec 28 '16 at 14:38
  • Possible duplicate of [git: switch branch without detaching head](http://stackoverflow.com/questions/471300/git-switch-branch-without-detaching-head) – Dan Lowe Dec 28 '16 at 14:46
  • @LuísFelipeNogoseke i've tried 'git push', 'git push 1.0', and even 'git push origin/1.0' but all give exactly the same result – Andy Dec 28 '16 at 15:03
  • Try `git push origin 1.0` -> note the space instead of the slash – bcmcfc Dec 28 '16 at 15:13

1 Answers1

2

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.

Nogoseke
  • 969
  • 1
  • 12
  • 24
  • 1
    bingo!! - I had a tag called 1.0 as well. i've set up the test again making sure tag names and branch names don't overlap and everything is working now. thank you – Andy Dec 28 '16 at 16:11