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.

Published by

Harsh

Harsh, also known to some as 'Qwerty' or 'QwertyManiac' online, is a Customer Operations Engineer at Cloudera, Inc.. Harsh is a fan of trance and electronic music, distributed systems and GUI programming, and loves to troubleshoot and hack on code in his free time. Formerly a KDE committer, he now is a committer on the Apache Hadoop and Apache Oozie projects and is a great fan of all Open Source Software.

2 thoughts on “A less known thing about cloning git repositories”

  1. 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.

Comments are closed.