Git: filename 'master' is ambiguous

I looked at all the other controversial issues with a pseudonym, and none of them seem to help. Why am I getting this warning?

$ git checkout master warning: refname 'master' is ambiguous. $ git show-ref master eef61c00da690f093063ac5a728e22fd21648104 refs/heads/master $ git branch -a checkers exercises * master $ git remote -v $ 
+33
git
01 Sep
source share
3 answers

TL; DR: save and delete tag, Ashutosh Jindal comments (see " Rename tag to git? "):

 git tag tag-master master git tag -d master 



Original answer:

Most of the sources that I see (for example, this FAQ ) point to the same reason:

When you try to check the local branch, you get

 warning: refname 'branch-name' is ambiguous 

This can happen if you create a local branch with the same name as the remote tag .
Git should check your local branch, but instead, it tries to check the tag, and it gets confused.

The initial import of several trees was problematic because they contained the same named branches and tags. Since then, we have addressed many of these issues: rename tags .

In your case, you do not have remote, but local tags named as your branch may be enough.

Uncertainty specified in gitrevision

<refname> , i.e. master , heads/master , refs/heads/master

The symbolic name of the link. For example. master usually means the commit object referenced by refs/heads/master .
If you have both heads/master and tags/master , you can explicitly say heads/master to tell Git what you mean.
With ambiguity, a <refname> is ambiguously eliminated by accepting the first match in the following rules:

If $GIT_DIR/<refname> exists, this is what you mean (usually only useful for HEAD , FETCH_HEAD , ORIG_HEAD , MERGE_HEAD and CHERRY_PICK_HEAD );

  • otherwise refs/<refname> if it exists;
  • otherwise refs/tags/<refname> if it exists;
  • otherwise refs/heads/<refname> if it exists;
  • otherwise refs/remotes/<refname> if it exists;
  • otherwise refs/remotes/<refname>/HEAD if one exists.

So check where master can be found in your repo.

And git checkout heads/master will always work.
Warning: by default, this will check the branch in DETACHED HEAD mode. See " Why git checkout with explicit" refs/heads/branch "give a separate HEAD? "

To avoid this and still use a single-valued ref, enter:

 git checkout -B master heads/master 
+43
Sep 01 '12 at 7:07
source share
— -

Although this does not apply to the situation with the OP, I got a warning refname is ambiguous after accidentally executing git branch origin/branch instead of git checkout origin/branch . This created a local branch named origin/branch , which made it ambiguous with the remote branch. The solution was as simple as git branch -D origin/branch (safe because -D works with local branches).

+15
Jan 22 '15 at 23:01
source share

It happened to me. I somehow had a .git / master file containing sha. I do not know how this happened, but when I deleted it, the error disappeared. If you carefully read the accepted answer, this is the “expected behavior”, but you will not see this .git / master if you do this, for example. git show-ref master, because it follows slightly different rules.

+13
Mar 05 '13 at 23:19
source share



All Articles