Harsh J

Memoirs of a QWERTY Keyboard

A less known thing about cloning git repositories


When you’re heading out to give back something to the world by cloning out repositories of code hosted by beautiful git servers around the world and making edits to it in order to submit a clean patch, you might wonder sometimes: Why on earth does cloning repositories take SO much time?

Well the answer is that a proper clone will fetch all changes that were ever made in the project’s history, and you areĀ receivingĀ all of that into your clone.

While this is okay with new projects you’re butting into, it might take a ridiculous amount of time when you’re cloning something that’s been for a long time and has ALL its history intact (for reasons best known by their true developers :))

If your contribution is going to be a simple quick-patch-and-go-smile (which is perfectly fine, if you ask me – all form of contributions are great!) you should use this lesser known option of git-clone called depth.

Use a clone command as so, for example:

# Use the -depth=n option with a small number, to fetch only those many changes
# counting backwards from HEAD.
git clone git://github.com/QwertyManiac/avroutils.git --depth=1

This will fetch only the HEAD of the repository as part of the objects download. Your download size and time would be greatly reduced thus.

Do note, however, that you may not be able to clone from this copy, nor pull or push from/to it. These form of clones are called ‘shallow clones’. Read more upon it here if you may want to.

Written by Harsh

August 29th, 2010 at 11:00 pm

Posted in Personal

2 Responses to 'A less known thing about cloning git repositories'

Subscribe to comments with RSS or TrackBack to 'A less known thing about cloning git repositories'.

  1. Yeah, good tip if you are not a contributor and looking to just poke around the code.


    30 Aug 10 at 1:26 pm

  2. I would not say this is a good way to poke around the code, project history with commit messages helps speed that process up too.


    30 Aug 10 at 7:35 pm

Leave a Reply