warning: refname 'HEAD' is ambiguous

Git

Git Problem Overview


I am new to Git and I seem to have one branch too many if I execute the following command:

warning: refname 'HEAD' is ambiguous.

I get the following output:

warning: refname 'HEAD' is ambiguous.
From github.com:dagda1/hornget
 * branch            master     -> FETCH_HEAD
warning: refname 'HEAD' is ambiguous.
warning: refname 'HEAD' is ambiguous.

If I execute git branch -a

I get the following:

HEAD
* master
remotes/emmekappa/master
remotes/origin/HEAD -> origin/master
remotes/origin/master

I am confused by the remotes/origin/HEAD -> origin/master.

What is this and how can I get rid of the ambiguous branch.

I got to this stage by performing a merge where I think I added the ambiguous branch.

Git Solutions


Solution 1 - Git

The problem is that you have a branch called HEAD which is absolutely dangerous, since that's the symbolic name for whatever branch is the current branch.

Rename it:

git branch -m HEAD newbranch

then you can examine it and decide what to do (delete it, or save under a descriptive branch name)

(The origin/HEAD remote branch is not a problem)

Solution 2 - Git

Also, this will delete the branch, if you just don't want it.

git branch -d HEAD

Use a capital -D to force the deletion:

git branch -D HEAD

Solution 3 - Git

If you have created a tag named HEAD using...

git tag HEAD

...you can just delete that tag using:

git tag -d HEAD

See this case: kerneltrap.org/git-tag HEAD

Solution 4 - Git

This means that you have a branch named "head". I had the same issue, I solved by doing the following command.

git branch -d head

Solution 5 - Git

Check references available in your git repository. You will observe two HEAD in your repository. This makes your branch with refname HEAD ambiguous.

git show-ref

Solution:

  • Rename the branch

     git branch -m HEAD <new_branch_name>
    

OR

  • Delete the branch

     git branch -d HEAD
    

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questiondagda1View Question on Stackoverflow
Solution 1 - Gitu0b34a0f6aeView Answer on Stackoverflow
Solution 2 - GitJosiahView Answer on Stackoverflow
Solution 3 - GitBengtView Answer on Stackoverflow
Solution 4 - GitstacksonstacksonstacksView Answer on Stackoverflow
Solution 5 - GitDarshanView Answer on Stackoverflow