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:
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.
You can clone a repository from GitHub.com to your local computer to make it easier to fix merge conflicts, add or remove files, and push larger commits. When you clone a repository, you copy the repository from GitHub.com to your local machine.
Open TerminalTerminalGit Bash. Create a bare mirrored clone of the repository. Set the push location to your mirror. As with a bare clone, a mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository.
To clone a branch in a git repository, start by cloning the master repository using the git clone command. Once complete, navigate into the repo directory. The command will show the branches that are available in the local repository. To view even the remote branches, use the -a flag.
I think you're looking for
git clone --reference=/path/to/existing/repo url
In git lingo this known as using "alternates". There are potential problems with this option, as mentioned in the git clone help but it may suit your purposes.
You may also be interested in Dustin's helper git-alternates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With