Speed up Git Clone with Shallow Clones

by Stephen Fluin 2010.03.01

Git is an excellent version control system. It is built on the principles of DVC, or distributed version control which means by default, your local copy contains all of the revision history for the entire repository. This is great because changes can be made, committed, undone, and even merged offline.

This property of git also has a potential downside when you are simply trying to access the latest version of a repository. In order to overcome this, git support a --depth parameter. This parameter will have the effect of preventing you from cloning it or fetching from it, and other repositories will be unable to push to you, and you won't be able to push to other repositories. These downsides ignored for a moment, having to work with only the recent history can be extremely desirable.

One concrete example of this would be the case where a user wants to compile wine. The official Wine Wiki has a git clone built right into the instructions. If you follow these instructions you will have the entire history, and it will take up around 200MB of disk space (this number will go up as time continues). By adding the depth parameter as follows, you can save more than half of this time by only checking out the most recent version of the repository.

git clone git://source.winehq.org/git/wine.git ~/wine-git --depth 1