Tags

  • AWS (7)
  • Apigee (3)
  • ArchLinux (5)
  • Array (6)
  • Backtracking (6)
  • BinarySearch (6)
  • C++ (19)
  • CI&CD (3)
  • Calculus (2)
  • DesignPattern (43)
  • DisasterRecovery (1)
  • Docker (8)
  • DynamicProgramming (20)
  • FileSystem (11)
  • Frontend (2)
  • FunctionalProgramming (1)
  • GCP (1)
  • Gentoo (6)
  • Git (15)
  • Golang (1)
  • Graph (10)
  • GraphQL (1)
  • Hardware (1)
  • Hash (1)
  • Kafka (1)
  • LinkedList (13)
  • Linux (27)
  • Lodash (2)
  • MacOS (3)
  • Makefile (1)
  • Map (5)
  • MathHistory (1)
  • MySQL (21)
  • Neovim (10)
  • Network (66)
  • Nginx (6)
  • Node.js (33)
  • OpenGL (6)
  • PriorityQueue (1)
  • ProgrammingLanguage (9)
  • Python (10)
  • RealAnalysis (20)
  • Recursion (3)
  • Redis (1)
  • RegularExpression (1)
  • Ruby (19)
  • SQLite (1)
  • Sentry (3)
  • Set (4)
  • Shell (3)
  • SoftwareEngineering (12)
  • Sorting (2)
  • Stack (4)
  • String (2)
  • SystemDesign (13)
  • Terraform (2)
  • Tree (24)
  • Trie (2)
  • TwoPointers (16)
  • TypeScript (3)
  • Ubuntu (4)
  • Home

    Shallow Clone vs. Partial Clone

    Published Feb 14, 2025 [  Git  ]

    Shallow Clone

    • Definition: A shallow clone only fetches a limited history of commits.
    • Use Case: When you don’t need the entire commit history of a repository. Useful for saving time and disk space.
    • How to Create:
      git clone --depth <depth> <repo-url>
      
      • --depth 1: Only fetch the latest commit.
      • Shallow clones can significantly reduce the size of the clone, but they might not support certain operations like checking out older commits or rebasing.
    • Example:
      git clone --depth 1 https://github.com/example/repo.git
      
      • This fetches only the latest commit for each branch.

    Partial Clone

    • Definition: A partial clone skips fetching large objects (e.g., binaries) until they are actually needed.
    • Use Case: When the repository contains large files or many objects you don’t need right away (e.g., in monorepos or projects with large media assets). Saves disk space while allowing you to work with the repo.
    • How to Create:
      git clone --filter=<filter> <repo-url>
      
      • Common filters:
        • --filter=blob:none: Skips all blobs (file contents) and only downloads them when accessed.
    • Example:
      git clone --filter=blob:none https://github.com/example/repo.git
      
      • This fetches only the repository structure and metadata, downloading file content on demand.

    Key Differences

    Aspect Shallow Clone Partial Clone
    Focus Limited commit history Skipping large blobs
    Speed Faster for small history clones Faster for repos with large objects
    Dis Space Save space by reducing hisotry Save space by delaying blob downloads
    Operations Limit Some opraions may not be supported All operations are supported