warning: remote HEAD refers to nonexistent ref, unable to checkout

前端 未结 11 1009
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 00:50

This seems like a popular error for different causes.

I\'ve got a simple bare git repo called \"kiflea.git\", I clone it like this:

git clone git://k         


        
相关标签:
11条回答
  • 2020-12-01 01:09

    The warning: remote HEAD refers to nonexistent ref, unable to checkout. means that the remote (bare) repository contains branch reference in the file called 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 (.git/HEAD or plain HEAD for bare repositories) 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).

    If you have shell access to your remote git repo, you can simply cd path/to/bare/git/repo; git symbolic-ref HEAD refs/heads/XYZ where XYZ is the branch name you want to use by default.

    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.

    0 讨论(0)
  • 2020-12-01 01:09

    I'd guess that it's the leading * in the commit log that is somehow fooling the remote server.

    I can browse around the repo's web interface using some of the menu links, but others fail with a 404 - Unknown commit object or similar, particularly from the summary page.

    See if you can amend that last commit message and then force push the update to see if that fixes it. There may be a bug in the server demon. If it does fix it it would be worth reporting on the git list git@vger.kernel.org (plain text messages only)

    0 讨论(0)
  • 2020-12-01 01:10

    I have had the same issue because I was not using anymore the master branch and it went lost in both my local and remote repository.

    The remote repository had still the HEAD set to master, I have changed it to one of the remote branch I actually use and everything works fine.

    If you can access your remote repository:

    • Go to your remote_repo.git;
    • Edit HEAD file
    • Change ref: refs/heads/master to ref: refs/heads/your_branch
    0 讨论(0)
  • 2020-12-01 01:10

    I had same issue when creating a bare repo.

    I solved it just cloning the repo, creating a local master branch and then pushing master to the remote repo.

    1) clone the repo

    $ git.exe clone --progress -v "the remote path" "my local path"
    

    2) create a master branch locally.

       $ git checkout -b master
    

    3) commit something in the local branch

    $ git add readme.md 
    $ git commit –m “Added readme”
    

    4) Push local master on the remote

       $ git push origin master
    
    0 讨论(0)
  • 2020-12-01 01:21

    For Gitlab, even it shows you are on a default branch (e.g. master) you might not actually be on it, setting it again fix it, like so:

    1. Create a new branch, maybe asd
    2. settings > repository > Default Branch, which shows the default branch is master
    3. Set it to asd
    4. Set it back to master
    5. Delete asd branch

    Done, now your default branch is master

    0 讨论(0)
提交回复
热议问题