Fast Git Clone

Fri 31 January 2014 | tags: git

Lots of tutorials nowadays recommend using git clone to get a project's source code, that's fine for little projects but for the big ones is a waste of bandwith, space, and more importantly, of your precious time.

Whenever you need to clone a git repo from the internet and you plan to just use the contents and no need for past history, then the good old git clone is a waste of bandwith, that command gets the whole repo history, that is every line change that has been commited since the beginning of development, you just need the latest state of files so let's tweak a little to simulate the "Download ZIP" button on the github page:

git clone --depth 1

This way you get the latest copy of a project's master branch, no history and minimize usage of network resources. That's fast!

From man git clone:

--depth <depth>
      Create a shallow clone with a history truncated to the specified
      number of revisions. A shallow repository has a number of
      limitations (you cannot clone or fetch from it, nor push from nor
      into it), but is adequate if you are only interested in the recent
      history of a large project with a long history, and would want to
      send in fixes as patches.

Comments !