Use shallow clone to reduce the download size of a GitHub repository

If you want to send a pull request to a certain project on GitHub, you first have to fork it to your own repository and then – in the most cases – clone it to your local machine.

If you’re contributing to a very active project with many commits, the size of this download will grow over the time. This is because the entire commit history of the project will be cloned to your machine as well.

Most likely you are not interested in the entire commit history, you just want to see the present state or the latest commits. In this case you have a good chance to reduce the download size by simply adding the option –depth to your git command. This is called a shallow clone.

Example:
Executing $ git clone https://github.com/OXID-eSales/oxideshop_ce.git (without the –depth option) will presently download 116.37 MiB from GitHub.

Using $ git clone --depth 10 https://github.com/OXID-eSales/oxideshop_ce.git will reduce the size to presently 36.39 MiB.

1

1 thought on “Use shallow clone to reduce the download size of a GitHub repository

    • Even better: If you only need the files without their history, for example to deploy it on a webserver:

      $ git archive --remote https://github.com/OXID-eSales/oxideshop_ce.git master
      --format=tar.gz | tar xfvz -

Leave a Reply

Your email address will not be published. Required fields are marked *