The Wayback Machine - https://web.archive.org/web/20240927195026/https://www.geeksforgeeks.org/shallow-clone-on-git-in-linux/
Open In App

Shallow Clone on Git in Linux

Last Updated : 03 Jun, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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

Bat – A Cat Clone with Syntax Highlighting and Git Integration
The 'bat' command is essentially a counterpart to the standard Linux command, 'cat'. 'Cat' is a default command found in most Linux distributions, primarily used for tasks such as text viewing and file concatenation. However, 'bat' surpasses the 'cat' command in several key aspects. It encompasses all the fundamental functionalities of 'cat' and in
6 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 repository. In this article, we will explore what git
5 min read
Difference between “git add -A” and “git add”
When working with Git, the git add command is used to move changes from your working directory to the staging area. However, there are different options and flags that can be used with git add, such as -A, which might lead to some confusion. In this article, we'll explore the differences between git add -A and git add. 1. Git add- CommandThe git ad
2 min read
GRV - Tool for Viewing Git Repositories in Linux Terminal
Git Repository Viewer or GRV is a cross-platform, free, and open-source GIT GUI client. It provides a terminal-based interface to search and view refs, commits, branches, tags, and diffs in a git repository. The behavior and style can be customized through a configuration file. GRV is written in the Go programming language and is available under GN
2 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 programmers who are working on source code togethe
2 min read
How to Install Git on Kali Linux
Git is an important version control system that is renowned for its reliability and cooperation capabilities. The process of installing Git on Kali Linux is straightforward and efficient, guaranteeing that it works seamlessly with your development process. We'll carefully walk you through each step in this extensive guide, enabling you to set up Gi
6 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 walk you through how to install Git on Red Hat Linu
4 min read
How to Clone Github Repository and Push Changes in Colaboratory?
If you are working with a Machine Learning project, the greatest bottleneck could be the lack of computational resources. With Google Colaboratory (Google Colab or Colab in short), now we have the freedom to use a GPU at your disposal. Here we are going to see how we can clone your GitHub repository into the Google Colab. To do so follow the below
2 min read
How to Clone a Project From GitHub using VSCode?
Cloning a project from GitHub is often the first step for developers looking to contribute to open-source projects or work collaboratively with their team. While there are various ways to clone a GitHub repository, using Visual Studio Code (VSCode) adds a layer of convenience and integration. In this article, we'll explore how to clone a project fr
2 min read
How to Clone a Project From GitHub Using Eclipse?
Cloning a project from GitHub using Eclipse is a simple process that allows you to seamlessly integrate your development environment with your GitHub repositories. Whether you're collaborating on a team project or exploring open-source repositories, Eclipse provides a convenient way to clone and work on GitHub projects directly from your IDE. This
2 min read
Difference Between Arch Linux and Kali Linux
Arch Linux is an open-source Linux-based Operating System that is freely available for use. It belongs to the Pacman-based Linux family. It is a light weighted OS for daily use and could even be used by professionals. It was first released in March 2002. It is a beginner-friendly Linux Operating System. Features of Arch Linux: Minimalist approach:
4 min read
Neofetch In Linux – Snap cool screenshots of your Linux
Neofetch is a fancy, highly customizable, and aesthetic command-line system information screenshot utility tool. Written in the Bash scripting language, it works inside a terminal window, on triggering up the command it by default displays the operating system, software, and hardware of your system on the right side of the column alongside an ASCII
4 min read
Exodus - Copy Linux Binaries From One Linux System
Exodus is an easy-to-implement program, that is used for bundling dependencies, and also helps to effectively copy Linux ELF binaries from one to another machine securely, and this is very handy when you don't have root access, also if there are issues in the availability of the packages in the Linux distribution, Commonly Server oriented distribut
3 min read
Basic CentOS Linux Commands in linux
CentOS is a free and open-source operating system that aims to provide a stable reliable, and community-supported platform for servers and other enterprise applications. In this article, we will be covering CentOS Linux basics commands and functions of CentOS and also we will look into the advanced commands. These CentOS commands allow you to manag
3 min read
Linux on Azure – Linux Distributions
Azure, the cloud computing platform from Microsoft, offers a playground for deploying and managing your Linux-based operating systems. Think of it as a canvas of boundless resources, security, and scalability, painted onto which you can unleash the boundless creativity and flexibility of Linux. This powerful synergy unlocks a world of opportunity,
10 min read
An Ultimate Guide to Git and Github
Highlights of the article: Introduction to GitGit Repository StructureGithubAccessing Github central repository via HTTPS or sshWorking with git - Important Git commandsIntroduction to Git For installation purposes on ubuntu, you can refer to this article: How to Install, Configure and Use GIT on Ubuntu? Git is a distributed version control system.
8 min read
Git - Changing History
Git provides a very important option of altering the commit history. As the master of git, you can control and make it function according to you. Git gives you the authority to change the order of commits, change messages, remove commits entirely. Moreover, it also allows you to manage the project's history. However, it is advisable to commit the w
3 min read
Introduction to Git Branch
Branching means diverging from the mainline and continue to work separately without messing with the mainline. Nearly every VCS has some form of branch support. In Git, a branch is simply a reference to the commit, where the following commits will be attached. Git vs SVN: In recent years, the use of git has risen tremendously. Unlike SVN, git allow
3 min read
Git Features
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 application and can modify changes to it which may b
9 min read
Getting changes from a Git Repository
Git allows performing various operations on the Repositories including the local repositories and remote repositories. The user when downloads a project to work upon, a local repository is created to store a copy of the original project. This local repository stores the changes that are being made by the user. This way, the user can edit the change
4 min read
Using Tags in Git
Tagging in GIT refers to creating specific points in the history of your repository/data. It is usually done to mark the release points. Two main purposes of tags are: Make Release point on your code. Create historic restore points. You can create tags when you want to create a release point for a stable version of your code. You can also create ta
2 min read
Patch Operation in Git
Git patch is a feature in git which enables you to create a patch file from a feature in one branch and apply it in another branch. A patch file has all the differences between the two branches. Using the patch file, we can apply the changes in a different branch. This can be visualized as - Suppose you are working on a project. The main project is
3 min read
Best Git Practices to Follow in Teams
We all know that Git is one of the most popular version control used by developers all over the world. Developers are using it for many years but not all developers know the best practices for using it. There are several ways to use git to communicate with your team. You can use these git best practices from a small team of two to ten developers. W
6 min read
Git - Filtering the Commit History
Git source code versioning tool provides a lot of features. One of the most important and useful features is log or history. We can use git log command in order to list, filter, view commit history in different ways. Here we will examine git log command usage in detail with examples. List Commit History: We will start with git log command without a
4 min read
Git-Secret - Go Script For Finding An API Key / Some Keywords In Repository
An API key is a simple encrypted string that recognizes an application without any administrator. They are useful for accessing public data anonymously and are used to connect API requests with your project for quota and billing. These API Keys are too sensitive as they are used in Authentication. A leaked API Key can cause several problems as this
2 min read
Essential Git Commands
When it comes to commands, there come numerous commands in a software developer head or one that is mastering over git but even only a few of them are used frequently in the enterprising domains that are used frequently by developers in order to boost workflow. So here we will be listing a couple of them prior to dividing them into categories in or
3 min read
Git Flow vs Github Flow
There are basically two ways to manage the software projects in GIT Git flow and GitHub flow. These two flows can help you manage your project and optimize your entire workflow in the team. GitHub Flow GitHub flow is really very simple to adapt as this flow doesn't have releases because your deployment to production happens every day. There are two
4 min read
Automating some git commands with Python
Git is a powerful version control system that developers widely use to manage their code. However, managing Git repositories can be a tedious task, especially when working with multiple branches and commits. Fortunately, Git's command-line interface can be automated using Python, making it easier to manage your code and automate common tasks. One p
3 min read
How to install git-crypt on Ubuntu?
git-crypt encrypts and decrypts data in a git repository in a transparent manner. When you commit a file, it is encrypted, and when you check it out, it is decrypted. With git-crypt, you may freely share a repository that contains both public and private information. git-crypt gracefully degrades, allowing developers without the secret key to clone
1 min read
Git - Squash Commits
In Git, squashing refers to combining two or more commits into a single commit. This is typically done to improve the organization and clarity of the commit history, especially when working on a collaborative project with other developers. In this article, we will review the feature git squashing, which is a great feature for arranging multiple com
2 min read
Article Tags :