Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
Shallow Clone on Git in Linux
Next article icon

Shallow Clone on Git in Linux

Last Updated : 03 Jun, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

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.


Next Article
Shallow Clone on Git in Linux

M

manavsarkar07
Improve
Article Tags :
  • Linux-Unix
  • GitHub

Similar Reads

    How to Install GIT in Conda?
    Anaconda is a free and open-source distribution of the programming languages Python and R programming languages for scientific computing, data processing, and data analytics. It includes Jupyter, Spyder, and a powerful CLI to manage the development environment. Git is a free, open-source, and most p
    2 min read
    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 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
    7 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
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences