About 2 years ago we moved our Gerrit 2.10 site to a new datacenter, copying over the repos as part of the process. This is probably the first time I've tried to access the "All-Users" repo, and I'm seeing the following error:
user@desktop=> git clone ssh://[email protected]:29418/All-Users
Cloning into 'All-Users'...
warning: remote HEAD refers to nonexistent ref, unable to checkout.
Other repos aren't experiencing this issue. Is there some way I can troubleshoot and remediate?
CodePudding user response:
Go to Gerrit > BROWSE > Repositories > All-Users > Branches and check if the HEAD is pointing to "refs/meta/config". Correct if needed.
CodePudding user response:
You have a Gerrit-specific answer (which is the one to use in this case), but if anyone stumbles across this question in a non-Gerrit context, here's what is going on and what you can therefore do.
When you run:
git clone <url>
(note the lack of a -b
argument), your Git software:
- creates a new, empty directory, in which the remaining steps run;
- runs
git init
to create an empty repository (one with no commits, nothing at all in it); - runs
git remote add origin <url>
to save the URL under the nameorigin
; - runs any
git config
steps called for (none are, in this case, but step 4 exists in case you add-c
arguments); - runs
git fetch origin
to copy all the commits from the Git that responded at the given URL; and - runs
git checkout
orgit switch
(depending on your Git vintage) to create one branch in your new repository.
Note that step 5, which copies all the commits from the other repository, does not copy any branches. Instead, it takes each of their branch names and changes these names into your own remote-tracking names. A remote-tracking name—which Git rather misleadingly calls a "remote-tracking branch name"—is not a branch name at all. It's just a way for your Git software to remember, in your repository, the branch names from some other Git repository.
After step 5 finishes, you have a repository, but you have no branches at all yet and no commit is checked out yet. It's now time for your Git to choose a branch name to create. Which branch name should your Git create for you? Git's answer is: whatever name you supplied as the -b
option argument. But you didn't supply a -b
and argument. So your Git asks their Git: Which branch name do you, other Git, recommend I use in this new repository I just made?
Here, the other Git recommended something ridiculous—probably refs/meta/config
as in Marcelo Ávila de Oliveira's answer. Your Git said to itself: "This is nutty, I can't use that." Your Git then gave up in a huff and printed:
warning: remote HEAD refers to nonexistent ref, unable to checkout.
instead of doing step 6.
To fix this—in a way that you control *even if you don't have access to the Gerrit server—you can either:
- provide a
-b
argument telling your Git which branch you'd like it to create when you rungit clone
, or - after this failure, simply run
git checkout main
orgit switch main
(substitute in whatever branch name you wanted).
In other words, this is a very mild error. It's just annoying. You simply have to do your own checkout since git clone
was unable to use the name they recommended. The clone has already worked!