Published on

Shallow Clone vs. Partial Clone

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

AspectShallow ClonePartial Clone
FocusLimited commit historySkipping large blobs
SpeedFaster for small history clonesFaster for repos with large objects
Dis SpaceSave space by reducing hisotrySave space by delaying blob downloads
Operations LimitSome opraions may not be supportedAll operations are supported