Question

I use git 1.8.3.2.

I use a bare "w1.git" repository to test git related things.

I did the following

 git clone -- file:///home/rohloff/git/w1.git w1_clone

So now I have got the following branches (leaving out SHA1 and commit messages):

 git branch -avv

 master                   [origin/master]
 remotes/origin/HEAD      -> origin/master
 remotes/origin/master

So now I did

 git branch origin/master

and to my complete surprise that works ?!

I now have got

git branch -avv

master                 [remotes/origin/master]
origin/master
remotes/origin/HEAD    -> origin/master
remotes/origin/master

Note how "master" now cleverly points to "remotes/origin/master".

But if I try to now create a topic branch with

git branch topic origin/master

I get (not surprisingly)

Warning: refname 'origin/master' is ambiguous.

So I am wondering:

  • Is there any way to tell git to forbid the creation of "ambiguous" branches ? Or is it simply my responsibilty to avoid creating such ambiguously named branches ?
  • With the "git branch topic" above: Is there any way to clearly specify which branch I mean ?

EDIT : It turns out the following is also allowed:

 git branch origin/master
 git branch remotes/origin/master
 git branch refs/remotes/origin/master

After these three commands it seems there is no way at all anymore to refer to "master" from the "origin" remote repository...

EDIT : It turns out this problem is right now (15 Feb 2014) discussed on the git developer mailing list. see

https://marc.info/?t=139237924400005&r=1&w=2

The proposal is to forbid something like this as long as someone does not use "-f".

Was it helpful?

Solution

  • I don't believe there is a built-in way to prevent creation of ambiguous branches. And even if there was such an option to git branch, if you create a local branch origin/foo when there's no remotes/origin/foo that's something that might change over time.
  • Yes, you can specify the fully-qualified names, i.e. refs/heads/origin/master and refs/remotes/origin/master. In fact, you can drop the initial "refs/" as e.g. heads/origin/master is unambiguous.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top