tags:

views:

771

answers:

2

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:

  1. the clone points back to the copied repository as its origin, but I want it to have the same origin as the copied repository
  2. 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.

+4  A: 

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.

Pat Notz
A: 

Use "git clone --mirror", then change it from bare to non-bare repository (rename repo.git to repo/.git, copy .git/config file, checkout working directory using "git checkout HEAD"). Note: I didn't checked if it works as intended!

Jakub Narębski