Archive for June, 2011

Getting just the tip of a remote git branch

Tuesday, June 7th, 2011

As projects move their code under git control, people get frustrated about being unable to do most basic operations they are used to perform with SVN or CVS. That’s a fact, so let’s see if I can relief some pain by sharing what I know or learn as I crawl the learning curve myself.

Yesterday I’ve met with Markus Neteler and he was complaining about being unable to checkout the release branch of QuantumGIS without filling up his laptop hard drive. He got me curious, so here are some numbers and a recipe.

An SVN checkout as of April 30  is 281 Mb in size, 1 of which being the .svn directory.

A full git clone at time of writing (June 7) is 330 Mb  in size, 200 of which being the .git database and  130 being the working copy (the “checkout”).

A full git clone contains all the data available in the original repository. Once you get the clone, you have all the branches and all the history. no need for any more bandwidth.

But Markus was only interested in a single branch, not the whole set, and he wanted no history either. So he could cloned just the objects referenced by the commit known as the release-1_7_0 branch and no further parents (back history). Here’s how you do:

 git clone --depth 1 --branch release-1_7_0 \
           git://github.com/qgis/Quantum-GIS.git
The resulting shallow repository (the .git directory) is 110 MB in size. Add 133 MB of working directory (yes, release-1_7_0 is 3 MB bigger than master) for a total of 243 MB disk space used.

NOTES:
  1. A shallow repository (one with short history) cannot be further cloned, but here are no problems pulling updates from the origin nor producing patches or pushing changes.
  2. If you don’t know in advance the name of the branch you can query it from the remote repository using git ls-remote
  3. Every git command has a manual page in the form: git-command (ie: man git-ls-remote)
Happy learning !