0
0
Gitdevops~7 mins

Partial clone for reduced download in Git - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes repositories are very large, and downloading everything takes a lot of time and space. Partial clone lets you download only the parts you need right now, saving time and disk space.
When you want to start working on a large project quickly without waiting for the full repository download.
When your internet connection is slow or has data limits and you want to save bandwidth.
When you only need specific parts of a repository, like a single folder or file, not the entire history.
When working on a shared project where many large files are rarely changed and can be fetched on demand.
When using continuous integration systems that only need parts of the code to run tests.
Commands
This command clones the Git repository but skips downloading file contents (blobs) initially, only fetching metadata and commit history.
Terminal
git clone --filter=blob:none https://github.com/git/git.git
Expected OutputExpected
Cloning into 'git'... remote: Enumerating objects: 100000, done. remote: Counting objects: 100% (100000/100000), done. remote: Compressing objects: 100% (50000/50000), done. Receiving objects: 100% (100000/100000), 20.00 MiB | 2.00 MiB/s, done. Resolving deltas: 100% (50000/50000), done.
--filter=blob:none - Avoid downloading file contents initially to reduce data transfer.
Change directory into the cloned repository to start working inside it.
Terminal
cd git
Expected OutputExpected
No output (command runs silently)
Initialize sparse checkout in cone mode to allow checking out only specific folders or files.
Terminal
git sparse-checkout init --cone
Expected OutputExpected
Sparse checkout initialized.
--cone - Simplifies sparse checkout to work with folder patterns.
Configure sparse checkout to only include the 'Documentation' folder in the working directory.
Terminal
git sparse-checkout set Documentation
Expected OutputExpected
Updated working directory.
Checkout the main branch, downloading file contents only for the sparse paths set.
Terminal
git checkout main
Expected OutputExpected
Switched to branch 'main' Downloading objects: 100% (500/500), 5.00 MiB | 1.00 MiB/s, done.
Key Concept

If you remember nothing else from this pattern, remember: partial clone downloads only metadata first and fetches file contents on demand to save time and space.

Common Mistakes
Running git clone without the --filter=blob:none flag for large repos.
This downloads the entire repository including all file contents, causing slow clone and large disk use.
Always add --filter=blob:none to clone only metadata initially for large repositories.
Not initializing sparse checkout before setting sparse paths.
Git will not apply sparse checkout rules and will check out the full repository.
Run git sparse-checkout init --cone before setting sparse paths.
Trying to access files not included in sparse checkout paths.
Those files are not downloaded or checked out, so they appear missing.
Add needed folders or files to sparse checkout with git sparse-checkout set.
Summary
Use git clone --filter=blob:none to clone only metadata and reduce download size.
Initialize sparse checkout with git sparse-checkout init --cone to control which parts of the repo to check out.
Set specific folders or files to check out with git sparse-checkout set and then checkout the branch.