0

I want to mirror a git repo 'main'. The mirrored repo just mirrors the main repo on different provider. that means when changes happens on the main the mirror repo on the new provider reflect the changes.

I tried

$ git clone --mirror git@example.com/old-upstream-repository.git
$ cd old-upstream-repository.git
$ ls
  HEAD  branches  config  description  hooks  info  objects  packed-refs  refs
$ git push --mirror git@example.com/new-location.git

but when I run the push command I get

remote: error: object 0a3: hasDotgit: contains '.git'
remote: fatal: fsck error in packed object
error: remote unpack failed: index-pack abnormal exit
To git@example.com/new-location.git

 ! [remote rejected]       develop -> develop (unpacker error)
 ! [remote rejected]       feature/2321-new-edit-for-all -> feature/2321-new-edit-for-all (unpacker error)
error: failed to push some refs to 'git@example.com/new-location.git'

I assume I am pushing a bare repo since I also get the message

fatal: this operation must be run in a work tree 
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
A.Dumas
  • 2,619
  • 3
  • 28
  • 51
  • Does this answer your question? [How to update a git clone --mirror?](https://stackoverflow.com/questions/6150188/how-to-update-a-git-clone-mirror) – mkrieger1 Aug 15 '22 at 16:39
  • no since the mirror is not possible in the first place as mentioned in ticket – A.Dumas Aug 15 '22 at 16:52
  • 1
    The message `contains '.git'` is worrysome to me. Do you actually have a directory (or file) called `.git` inside your repo? I'm pretty sure it's impossible to create such a situation, but if you got into that situation, somehow, I could see it being a problem. To answer this question, try `git ls-tree -r develop` and see if `.git` is included in the listing produced. – joanis Aug 15 '22 at 19:20
  • What do you mean by "mirror is not possible"? With `git clone --mirror` you have created a mirror repository. – mkrieger1 Aug 15 '22 at 19:52
  • Your mirror clone is a bare clone (all mirror clones are bare clones). Your issue has nothing to do with mirroring, and everything to do with a new (in 2018 or so) requirement that Git now enforces: a Git repository *must not* contain another Git repository. This rule was always in place, but in the distant past (pre 2018 or so), there were ways to cheat the check: presumably someone used one of those. This means that you have a poisonous repository and new servers refuse to store it. You got it stored on your existing server before the rules were tightened. – torek Aug 16 '22 at 07:10
  • Since you cannot change the existing repository, your only hope is to discard the old repository entirely. Make a new and improved repository (using `git filter-repo`, perhaps) that does not violate the Git rules. Install this repository into all places (all mirrors and all clients who are doing work need to switch to the new one), and you can then mirror this new repository. It's a big pain in the , but that's what happens when you have a bad repository. – torek Aug 16 '22 at 07:14
  • @torek Thanks. that explained it. Is there way to find the poisonous part since I have not been able to find any folder with `.git` with `find ./ -iname .git`. There is no folder. – A.Dumas Aug 16 '22 at 12:28
  • It's no doubt in some old commit. You'll have to look through older commits to see which ones have `.Git` or `.giT` or whatever it is (the casing trick is what got past the old Git checks). – torek Aug 16 '22 at 12:32

0 Answers0