Getting just the tip of a remote git branch

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 !

Tags: ,

4 Responses to “Getting just the tip of a remote git branch”

  1. markusN says:

    Wow, strk, that’s really a timely service! Thanks so much for taking care of figuring out the git parameters for me/us power-lurkers in the QGIS development scene :)

  2. Flimm says:

    Great tip, thanks!

    Two nitpicks:

    1. Use two dashes, not one: git clone –depth 1 –branch release-1_7_0 git://github.com/qgis/Quantum-GIS.git

    2. I’m sure you probably meant MB, not Mb (bytes, not bits).

    I’m now going to try this in earnest.

  3. strk says:

    Thanks Flimm, I’ve fixed both issues (the two dashes was actually a wordpress bug transforming them at rendering time)

  4. Ian C says:

    How would you switch to a different branch while retaining the depth of 1? We use Mediawiki and don’t want to checkout the entire repository. Thanks.

Leave a Reply