Clone a repository without getting the entire history

Written on by Mandeep Singh in Improving Workflow

Git has a feature that we call Shallow Clone; this allows us to make a clone of a repository without taking in the entire history of commits/logs with it. This helps in a couple of ways; first, it decreases the size of the complete repository quite a bit, and secondly, because of decreased size, it also makes the cloning faster, and you can get started working on it faster. To do this, clone using the --depth option when cloning, like this:

git clone <repository URL> --depth 1

The --depth parameter allows you to specify how deep you want to go. So you can have some layers of commits, by increasing the depth count:

git clone <repository URL> --depth 3

Now doing this does have its perks, but at the same time, as you lose all history, you can not see who committed what and also the original authors lose credits (in a way) for their work. I would personally recommend you doing this in cases when you have a huge repo to clone, and losing history does not affect you in any way, like downloading a prebuilt app for personal purposes.

Other uses of this solution

  • How to create a shallow clone of a git repository

Sign up below to receive updates, tips and more handy tutorials. It’s good stuff & I don’t spam.