Skip to content
Related Articles

Related Articles

Shallow Clone on Git in Linux

View Discussion
Improve Article
Save Article
  • Last Updated : 03 Jun, 2022
View Discussion
Improve Article
Save Article

Git is tracking-based software used to track the changes made in a project. It is a distributed version control system. Software developers use it to collaborate on source code remotely. This allows the developers to create the software even when they are working professionals and contribute to the open-source.

What is Shallow Clone on Git?

Shallow Clone on Git solves the problem of large git binary files. Some projects have huge sizes, but the shallow clone reduces the size of the git. A shallow clone specifies the depth that the developer wants to go and git will get only the latest files until the user wants. In the shallow clone, we don’t get all the revisions in the git. That is sometimes beneficial but sometimes problematic. Because we may conflict with the files because we don’t have the history of revisions.

Let’s understand Shallow Clone on Git through various examples:

Example 1:  Clone the Django as normal and as a shallow clone to see the size difference

In the following example, we will clone the Django as normal and as a shallow clone to see the size difference.

Step 1: Clone the Django repository.

git clone https://github.com/django/django.git

Step 2: Use the following command to check the size.

du -sh django/

The output is as follows:

 

Step 3: Shallow clone the same Django repository.

git clone --depth 1 https://github.com/django/django.git

Step 4: Use the following command to check the size.

du -sh django/

The output is as follows:

 

Hence there is a huge difference. The original is 303 MB and the shallow one is just 80 MB.

Example 2: Clone the scikit-learn as normal and as a shallow clone to see the size difference

In the following example, we will clone the scikit-learn as normal and as a shallow clone to see the size difference.

Step 1: Clone the scikit-learn repository.

git clone https://github.com/scikit-learn/scikit-learn.git

Step 2: Check the size by using the following command.

du -sh scikit-learn/

The output is as follows:

 

Step 3: Shallow Clone the scikit-learn repository.

git clone –depth 1 https://github.com/scikit-learn/scikit-learn.git

Step 4: Check the size.

du -sh scikit-learn/

The output is as follows

 

Again there is a huge difference in the repository sizes as the original is 166MB whereas the shallow clone is just 31 MB.

Example 3: Clone multiple branches of the Django repository

In the following example, we will use the –no-single-branch flag. By default, the shallow clone assumes the depth for a single branch, but if –no-single-branch flag is provided, depth is applicable for all the branches. So we will shallow clone multiple branches of the Django repository.

Step 1: Use the following command for a shallow cone with multiple branches.

git clone –depth 1 –no-single-branch https://github.com/django/django.git 

Step 2: Now check the size:

du -sh Django/

The output is as follows:

 

Step 3: We can see the drastic increase in the size because of multiple branches. To check them enter the following command:

cd django && git branch -a

The output is as follows:

 

Hence we can see that we got all the branches with their details with –no-single-branch. Hence the size increased of the repository.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!