Shallow Clone on Git in Linux
Last Updated :
03 Jun, 2022
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.
Similar Reads
Git Shallow Clone: Optimizing Repository Size
Git is an important tool for version control, known for its ability to manage projects with complex histories efficiently. However, as projects grow and their histories expand, the size of the repositories can become larger, impacting performance and increasing clone times. This is where Git's shall
4 min read
How to Install Git in VS Code?
Git is a free and open-source distributed version control system. It is designed to manage every type of project even a small or a large project with good speed and efficiency. It is more focused on distributed development of software so that more developers can have the access to the source code an
2 min read
How to install Git on Redhat Linux 9?
Git is a widely adopted version control system that enables developers to efficiently track changes in their codebase. Installing Git on Red Hat Linux 9 is a crucial first step for any developer looking to manage projects, collaborate with teams, and control version history seamlessly. Here, weâll w
4 min read
What is Git Clone?
Git, a distributed version control system, is widely used for tracking changes in source code during software development. One of the fundamental commands in Git is git clone. This command is important for developers to collaborate on projects by allowing them to create a local copy of a remote repo
5 min read
How to Install Git Large File Storage on Linux?
Managing large files in Git can be challenging, but Git Large File Storage (LFS) offers a solution. Git LFS handles large files by replacing them with text pointers inside Git while storing the actual content on a remote server. This guide will walk you through the process of installing Git LFS on a
3 min read
Git - git-show Command Line Utility
Git is a free and open-source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. Git relies on the basis of distributed development of software where more than one developer may have access to the source code of a specific ap
3 min read
Is Our Code Secured in Git?
Git is an essential tool for managing and tracking code, but its widespread use also makes it a target for potential security threats. Ensuring the security of your code within Git repositories is very important whether youâre working on open-source projects, private business applications, or sensit
6 min read
How To Install "git-gui" on Linux?
Git is a FOSS (Free and Open Source Software) that is used for version control of any set of files, typically, the source code of software projects. Git is a version control system for recording changes in any group of files. During software development, it's generally used to coordinate work among
2 min read
How to Install GIT on Chrome OS?
Git is a type of version control system. There are two types of version control systems are present. One is Centralised & another one is distributed. Centralized VCs are less effective in nature. So, Distributed VCs now replaced the Centralised version. It is a good example of a distributed vers
3 min read
How to Install GIT Lens on VS Code?
Gitlens is a popular open-source extension available for Git. Though it can not be installed independently without VS Code. VS Code is a widely used Ide for various programming languages. Along with these, VS Code can also be used as the terminal of Git. But developers are used Git Bash normally as
2 min read