git clone gives warning: “remote HEAD refers to nonexistent ref, unable to checkout.”
This warning: “remote HEAD refers to nonexistent ref, unable to checkout.” happened to me today and since it was an odd enough warning (I’ve never seen it before in all my years of work with git) I thought it’s worth describing the situation here and how I solved it.
I cloned a remote git repository from a public server (it was stlinux’s u-boot source) onto my workstation. I then added a branch to it and created my changes on it, then did a commit. After that I made a place for the repository on our organization’s git server and pushed the entire repository there:
git push –all our-git-server
At that point browsing the repository in gitk it looked fine – every branch had a remote branch. One thing I noticed though, and it appeared strange to me was taht this repository did not have a ‘master‘ branch, but at that point I disregarded that fact as it all appeared to work just fine…
A colleague of mine then decided to clone this repo and got the warning in question:
warning: remote HEAD refers to nonexistent ref, unable to checkout.
That did look strange as there were no errors at all until that point. I went on to try and clone the repo onto my machine and got the same warning: remote HEAD refers to nonexistent ref…
At that point I remembered that the repository did not have a ‘master’ and it occured to me that perhaps that is the problem. The message did sound like it tries to checkout something that does not exist in that repository and ‘master’, being absent from it and being the default branch which is always being checked out matched perfectly that description.
I then added a master branch to the repository and it all worked and the “unable to checkout” warning did not appear again when I tried to clone it.
So adding a master branch definitely solves the problem…
The part which is still not entirely clear for me is – how come cloning the original repository did not generate the remote HEAD refers to nonexistent ref, unable to checkout.
warning? If a missing master branch is what causes this bug to manifest it self (because if that is the real problem then it is definitely a bug in git – nothing says that a repo MUST have a master branch…) – if a missing master is what causes this then this problem should have happened also when I cloned the original repository from git://git.stlinux.com/stm/u-boot.git…
If anyone has an explanation to this misterios “nonexistent ref” warning I’d sure love to hear it 🙂
4 Responses to git clone gives warning: “remote HEAD refers to nonexistent ref, unable to checkout.”
Leave a Reply Cancel reply
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum
I faced a similar problem, and also noticed that the remote repo did not have a master branch, whereas it used to. So I tried to recreate the remote master branch by simply checking out to my local master, and pushing it to the remote repo but I get the following:
Total 13 (delta 11), reused 0 (delta 0)
error: unable to resolve reference refs/heads/master: No such file or directory
remote: error: failed to lock refs/heads/master
To git_user@10.128.40.81:/home/git_user/MyProj.git
! [remote rejected] master -> master (failed to lock)
error: failed to push some refs to ‘git_user@10.128.40.81:/home/git_user/MyProj.git’
What I don’t get is how is the master branch missing to begin with, and secondly how can I add a remote master branch? Any input you could give me would be appreciated.
I just received this nice message as well. I tried to fix it by adding a Master branch on our git-server but somehow that didn’t work. I can’t clone it to add a master or any branch. So how did you add the Master branch? Can you do this on the bare git repo where you clone from???
Hello All,
I also faced the similar issue and found out two resolutions to solve it.
Solution 1:
———–
Make sure the Submit/Push privileges are appropriately assigned to users/groups in Gerrit for the current project. Then make an initial commit on the cloned repo, copy that commit-id and create a new branch in Gerrit – Admin->Projects->Branches->Create New Branch by giving Branch Name as master and Initial Revision as copied commit-id. This creates master branch on repo. And further clones will not get the warning mentioned above.
Solution 2:
———–
While creating the project,
ssh -p 29418 gerrit create-project –name –empty-commit # –empty-commit creates the initial commit and master branch gets created.
You refer to gerrit in your comment…. I know of gerrit but have never used it. I know its’s some sort of web front-end to git providing code review and tracking features… Does your comment apply to a pure-git system or it’s gerrit-specific?