The warning: remote HEAD refers to nonexistent ref, unable to checkout.
means that the remote (bare) repository contains branch reference in the file HEAD
that does not match any published branch in the same repository.
Note that the warning only means that git didn't do checkout. The cloned repository is otherwise just fine. Just do git branch -a
to see possible branches and git checkout the-branch-you-want
to workaround the issue.
This usually happens because the default contents for that file is ref: refs/heads/master
which says that if somebody is going to clone
this repository, they should by default clone the branch refs/heads/master
. By default Git will create local branch without the refs/heads/
prefix (that is, master
by default). Try git help symbolic-ref
for more information.
The problem with this situation is that Git does not provide a method for modifying remote symbolic refs so either you use something the Git hosting provider has implemented (e.g. Settings - Default branch in GitHub if you have admin rights) or you have to use branch name master
as the default branch (because that's the default value for that symbolic ref).
One way to hit this issue is to create a new remote bare repo with no commits and then do git push name-of-the-remote my-special-branch-name
which will result in bare repository containing a single branch my-special-branch-name
but the HEAD
symbolic ref still contains the default value pointing to master
. As a result, you'll get the aforementioned warning.
see : this post