Import branch onto shallow git clone

Cloning a git repository can be bandwidth consuming and really heavy task when resolving deltas.

Shallow clones offers alternative by retrieving only partial history from a repository. This will download less objects and require less computing time.

If you only want current version:

git clone --depth=1 repository

But shallow clones have many limitations as stated: “you cannot clone or fetch from it, nor push from nor into it” (see Git Clone)

However, you could still import a forked repository into a local branch if the fork point is common to the two trees.

git add remote forkedrepository git://thefork
git fetch forkedrepository remote:newlocalbranch

At this time, if you get an “error. connection reset by peer” then your local repository doesn’t contain enough refs.

If keeping as-is your current shallow clone content isn’t mandatory, you could easily rebuild it. Start cloning the forked repository, and let it run until he finished counting number of “objects”.(*)

git clone git://thefork tempdir

Then just use the object number value as depth. This value can’t be larger than number of commits 🙂

git clone --depth=<number of objects> repository

(*) There might be an easier way to count without starting a clone process, but since it’s ran on remote server, I have no idea on how to trigger it.