I am doing some work to track down a perceived bug in a git support tool, and I want to copy a repository (possibly many times) for experimental purposes. I would like for hard links to be created to the original repository object database so as not to waste disk space storing multiple copies of identical objects with identical SHA values. git clone accomplishes this nicely, but unfortunately I can't seem to find a way to make git clone give me a new copy of the repository set up like the original repository:
- the clone points back to the copied repository as its origin, but I want it to have the same origin as the copied repository
- the clone winds up with only one branch, but I want it to have all of the branches of the copied repository
I can ameliorate some of this by using git clone --mirror, but that will only work to create a bare repository, and the repository I am experimenting on is not bare, and the support tool I am trying to debug does not function on bare repositories.
I thought about writing a quick shell loop to make a new object database full of hardlinks to the original object database, and then copying everything else out of the original .git directory, and then doing a git checkout, but I am concerned that this is complicated enough to be error prone and that I don't know enough to perform this kind of low-level surgery correctly and will build a repository with subtle errors. Should this approach work, in theory?
Better yet, is there a way to pass options to git clone to make it do what I want?
Is there a way I can create a new repository but tell it that its object database is in another directory, basically telling it to share the object database from the original repository?
If none of the above works, then I'm left with only a cp -pr, which is going to consume a lot of space and be time consuming.