49

I am using git as a frontend to Subversion (via git svn).

So, for every svn trunk/branch I have remote branch in git named "remotes/xxx". For example "remotes/trunk", "remotes/coolfeature".

Now I want have one "default" local branch for every remote branch, to use it for dcommit. The problem is that I want such branches to be named after Subversion branches, like "trunk", "coolfeature", so I have the following branches in git:

trunk
coolfeature
remotes/trunk
remotes/coolfeature

The problem is that every time I reference "trunk" or "coolfeature" git complains branch name is ambiguous. Not a big deal, but I feel uncomfortable.

The question is, how can I deal with that warning, assuming that simply renaming branches is not what I want to do. What are the best practices for such cases?

jub0bs
  • 60,866
  • 25
  • 183
  • 186
Ivan Dubrov
  • 4,778
  • 2
  • 29
  • 41
  • 3
    I'm not sure. I avoided this by just choosing different but similar names. However, you could try using `refs/heads/trunk` or maybe even just `heads/trunk`. I think that should work. – Tyler Jan 10 '11 at 07:00
  • Related: https://stackoverflow.com/questions/26046698/git-refname-origin-master-is-ambiguous – jub0bs Jan 11 '19 at 06:19

4 Answers4

40

If you pass the --prefix=svn/ flag to the git svn clone command, then all of the Subversion branches would be named like remotes/svn/branchname. If this is acceptable to you, it fixes the "refname is ambiguous" warning. It also gives you a nice way of referring to the remote svn branches, as in for instance if you want to create a local tracking branch it would be something like:

$ git checkout -b branchname svn/branchname

The local branch then has the same name as the remote svn branch, and no ambiguous refname problem.

Jason Voegele
  • 1,918
  • 1
  • 19
  • 18
  • 19
    How can I fix a repository I already cloned to have `--prefix=svn/`? – Elazar Leibovich Mar 29 '11 at 11:54
  • I just cloned into a new directory and then fetched the local branches I had from the other directory: git fetch ../other_dir branch_name:branch_name --- tab completion is great for the branch names too. – EnigmaCurry Sep 21 '11 at 19:07
  • 1
    If you have already created a branch with the same name, you can rename your branch with this command: git branch -m [currentName] [newName] – MikeD Mar 10 '14 at 18:27
  • As of git 2 the svn prefex is set by default to svn/ if you want a different prefix or want to track multiple svn repo's make sure you set it during the clone OR via .git/config – Narrim Apr 20 '15 at 01:18
13

If you just want to get rid of warning, set core.warnAmbiguousRefs to false:

git config --global core.warnambiguousrefs false

If you want this behavior only for single repository, omit --global flag.

max
  • 33,369
  • 7
  • 73
  • 84
  • I probably violated all all known/unknown rules here, but I tried "git tag -a HEAD -m 'Start of repo'" on a new repo, after which I received the OPs error message. The fix described in this post allowed me to keep working. – bakoyaro Mar 25 '13 at 12:16
1

To avoid the conflict messages, when referring to local branches, prefix them with heads/

for example, the conflicting branch topic

$ git diff topic remotes/topic
warning: reframe 'topic' is ambiguous.
...

becomes

$ git diff heads/topic remotes/topic
...
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
Alex Brown
  • 41,819
  • 10
  • 94
  • 108
1

It can be possible that you have another 'trunk' and 'coolfeature' as a tag. In this case, git doesn't know if you refer to branch or tag. Rename the tags and check if git doesn't report "ambiguous" name

Octavi Fornés
  • 599
  • 5
  • 3
  • This is not the case for me. `.git/refs/` contains unambiguous names. I don't have any tags. What is causing git to complain in first place? – Frederick Nord Sep 15 '14 at 07:10