A mirror is a spare copy of your code, kept on a second server, so the work is still there when the first one goes away. I keep one for every repo that matters to me, and I had been quietly assuming they worked. Then an import returned 200 and gave me an empty repo. A push exited zero and carried 208 of 359 branches. Those are the same fault in different clothes, and both cost me an afternoon of trusting a status code.
I keep a set of mirrors, and each one is a repo from a forge I do not control, copied into a forge I do. The point is not tidiness. The point is that the code outlives an account suspension, a policy change, or a project that vanishes upstream.
A mirror is only worth having if it is complete, and complete is a different question from whether the tool said it worked. The tool answers for the part it did, and it answers that part accurately. Nobody answers for the part it skipped, which is the part you will want on the day the source is gone.
The import that lied
Ask a forge to import a repo by URL and it does not copy anything yet. The API answers at once, because the answer is a receipt and not a result. Then the clone starts in the background, after the receipt has been filed. If the clone fails, the receipt still stands. What you keep is a shell: a name in the list, a page, a clone URL, and no commits at all.
Nothing about that shell looks wrong from the outside. It opens, and it offers you a clone command. The page looks finished, because a page is cheap to finish. The 80 that imported correctly looked much the same, which is the whole trouble.
The only way to know is to ask the repo about itself.
GET /api/v4/projects/:id → empty_repo, import_status, default_branch
An empty_repo: true next to an import status of failed is not a mirror. It is a name with a page. Mine had been sitting there for days, looking exactly like the ones that worked.
The push that lied
The second fault was quieter, and it is the one I would repeat if I had not written it down. A clone creates 1 local branch, which is the default branch. The other branches stay on the server as named pointers, which git calls refs, and your copy knows them only from a distance. When you push, git sends the branches you hold as local refs. So a push from a fresh clone sends 1 branch and reports a clean result.
Here is the command I used to think was the fix.
git push <remote> +refs/heads/*:refs/heads/*
It reads like all branches. It means all branches I have here, and after a routine clone that is 1. A repo with 359 refs arrived at the far side with 208. The command exited zero, so the tool reported success, because the push it ran did succeed. Git answered the question I asked. I asked the wrong one.
The fix is to fetch everything into a private namespace first, then push that namespace. A namespace is a second set of names inside the same repo, out of the way of the branches you work on. So the fetch fills it without touching your checkout.
git fetch origin '+refs/heads/*:refs/mirror/heads/*' '+refs/tags/*:refs/mirror/tags/*'
Then push the holding area and nothing else.
git push <remote> '+refs/mirror/heads/*:refs/heads/*' '+refs/mirror/tags/*:refs/tags/*'
Now the push carries what the fetch brought down, not what happened to be on my disk. That is the difference between copying the repo and copying my view of it.
How I check now
Not with exit codes, and not with a picture of a project page. A picture proves a page exists, and the page existed when the repo was empty. I compare what each side actually holds.
The tool’s own log is the wrong place to look, and this is the part I had to learn twice. A log records what the sender tried, in the order it tried it, and it does that job well. What it cannot record is the state of the other machine, because it never asked. So the useful check runs on the far side, against a list the far side made.
git ls-remote <source> > a.txt
git ls-remote <target> > b.txt
Then I drop the lines that can never match and diff the rest. Three kinds of line never match. Pull request refs exist on one forge and not the other. Peeled tag lines end in ^{}, and they are worked out from the tag rather than stored. Pipeline refs exist only on the server side. Remove those 3 groups and the two maps should agree, ref for ref, hash for hash.
identical refs: 2 of 2
differing: none
That is a claim I can defend later, because it says what was compared and not what was attempted.
Why this matters
A mirror is insurance, and insurance you have never tested is a story you tell yourself. The bad case is not a tool that breaks. A tool that breaks is loud, and you go and fix it. The bad case is a tool that half works and reports success, so the gap sits there until the day you need the copy. That is the worst day to find out, and it is usually the only day this kind of fault shows up.
The same instinct applies to backups, exports and any other copy. A file that exists is not a service that can be restored. A repo that exists is not the code being in it.
The cost
Ref comparison is cheap. It is 2 ls-remote calls per repo and a text diff, so 70-odd repos take a couple of minutes, and most of that is the network. I run it weekly on a schedule, and it stays quiet when everything matches, which is the only kind of monitoring that survives being ignored.
The full cache build is a different order of cost, because it copies objects and not just refs. The first run is about 16 GB and half an hour, and one enormous repo eats most of both. After that it is minutes, because only the refs get negotiated and the objects are already on disk.
The catch
Ref equality proves the two sides point at the same commits. It does not prove the objects behind those commits are still there, and it does not prove the mirror can be cloned. The cheap deeper check is to clone one repo from the mirror and build something from it, on a schedule that rotates through the list. A build is not proof, but it costs little and it catches more than a green tick does, and a green tick has never caught anything.
And a mirror is a copy, not a backup. If the source is wrong, the mirror is a faithful copy of wrong, which is why the comparison runs both ways instead of trusting either side.
This is the same lesson as a record that describes the world rather than proving it. The feed says a flaw is active. The mirror says the push succeeded. Neither of those statements checks the thing you actually care about, which is whether the code is now on the far side or not.
