Ambiguous Names with GIT?

I’m trying to check out one of my local branches, named TEAM20-lab2-release. When I try to do this, I get an ambiguous refname error:

$ git branch TEAM20-lab2-release
warning: refname 'TEAM20-lab1-release' is ambiguous.
fatal: Ambiguous object name: 'TEAM20-lab1-release'.

Here is the list of my branches:

  • Git: Copy source code to new branch without history
  • How to create a new source code branch using TFS API?
  • Git: How to merge a small, but very old branch?
  • What is the simplest way to do branching and merging using TortoiseSVN?
  • Is it possible with Git to retrieve a list of tags that exist only in a certain branch?
  • Sometimes git will track all remote git branches as local branches without me asking to. What happened?
  • $ git branch -a
      TEAM20-lab1
    * TEAM20-lab1-release
      master
      remotes/origin/HEAD -> origin/master
      remotes/origin/master
    

  • When do you make your first commit?
  • Can I git-svn clone an svn repo with multiple standard directory layouts
  • Git under windows: MSYS or Cygwin?
  • What are the git concepts of HEAD, master, origin?
  • Git patch Java Imports
  • Visual Studio 2015 Solution Explorer not refreshing Git changes upon commit
  • 3 Solutions collect form web for “Ambiguous Names with GIT?”

    It usually is because you have the same name (than your branch) used in another namespace:

    • like the “remotes” namespace: the name of a remote repo as illustrated by this SO question.
      (Hence davitenio’s request for git branch -a in the comments)
    • or the “tags” namespace”: having a tag named after a branch can also trigger that message (see this blog post)

    Update 2016: Git 2.12 (Q1 2017) won’t show any error if a branch and a tag are sharing the same name.

    See commit b284495 (31 Oct 2016) by Dennis Kaarsemaker (seveas).
    See commit eef2bda (28 Oct 2016) by Junio C Hamano (gitster).
    (Merged by Junio C Hamano — gitster — in commit 6c18dd4, 27 Dec 2016)

    push: do not use potentially ambiguous default refspec

    When the user does the lazy “git push” with no parameters with push.default set to either “upstream“, “simple” or “current“, we internally generated a refspec that has the current branch name on the source side and used it to push.

    However, the branch name (say “test“) may be an ambiguous refname in
    the context of the source repository — there may be a tag with the
    same name, for example.
    This would trigger an unnecessary error without any fault on the end-user’s side.

    Be explicit and give a full refname as the source side to avoid the
    ambiguity.
    The destination side when pushing with the “current” sent only the name of the branch and forcing the receiving end to guess, which is the same issue.
    Be explicit there as well.

    to get you started locating ambiguous refs

    function branchid() 
    { 
        echo $(basename "$(dirname "$1")")/$(basename "$1"); 
    }
    
    for ref in $(git for-each-ref | cut -f2)
        do echo -e "$ref\t$(branchid "$ref")"
    done | 
        sort --key 2 | uniq -Df 2
    

    I got the same error message when trying to set the upstream branch for a local branch.

    cgd@flavia-cgd-mobi:~/Projects/reporter$ git status
    On branch master
    
    nothing to commit, working directory clean
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git branch --set-upstream-to gerrit/master master
    warning: refname 'gerrit/master' is ambiguous.
    fatal: Ambiguous object name: 'gerrit/master'.
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git remote -vv
    gerrit  ssh://cgd@gerrit.server:29418/reporter (fetch)
    gerrit  ssh://cgd@gerrit.server:29418/reporter (push)
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git branch -a
      gerrit/master
    * master
      remotes/gerrit/master
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git branch -d gerrit/master
    Deleted branch gerrit/master (was 1234567).
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git branch --set-upstream-to gerrit/master master
    Branch master set up to track remote branch master from gerrit.
    
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git fetch
    cgd@flavia-cgd-mobi:~/Projects/reporter$ git status
    On branch master
    Your branch is up-to-date with 'gerrit/master'.
    
    nothing to commit, working directory clean
    

    As you can see I somehow created a local branch called gerrit/master which caused the conflict since git could not decide whether to track the local branch or the remote one. Deleting the erroneous branch fixed the thing and made me happy again.

    Git Baby is a git and github fan, let's start git clone.