PREP WITH PROOF
Menu
DEVOPS / PRACTICAL GUIDE

Git Sparse Checkout vs Partial Clone: A Hands-On Guide

Learn when to use Git sparse checkout, partial clone, or shallow clone. Run a local Bash lab to see which blobs Git downloads and when.

THE QUICK ANSWER

Sparse checkout chooses which tracked paths appear in your worktree. A partial clone with --filter=blob:none defers downloading file contents until Git needs them. A shallow clone limits fetched commit history. Use the first two together when you want a small worktree and fewer initial blob downloads without deliberately cutting off history.

Three Git settings, three different boundaries

You open a monorepo to fix one service. The clone spends time transferring files from projects you will never touch, and then your editor starts indexing a checkout full of unrelated code. Those are two different costs. Sparse checkout changes the second one. A partial clone can change the first. A shallow clone addresses yet another cost: the amount of commit history fetched.

Think of a commit as a snapshot that refers to trees and blobs. Trees describe the entries in directories; blobs hold file contents. Your local object database stores those pieces, while the worktree contains the files you can open and edit. A path can belong to the current commit, have no file in the worktree, and either have or lack its blob locally. That last distinction is the one a directory listing cannot show.

These settings can be combined. First decide which costs you need to reduce and which capabilities your workflow needs to retain. A developer investigating a regression may need extensive history, even when the bug lives in a single service. A CI job that only packages the current revision may have a very different requirement.

SettingWhat it limitsWhat to check first
Sparse checkoutTracked paths populated in the worktreeWhich directories does the task actually read?
Partial clone with --filter=blob:noneBlob contents transferred before Git needs themDoes the server support filtering and remain reachable?
Shallow clone with --depthThe fetched commit historyWill the job need older commits, tags, or a merge base?

Already have a clone? Start with sparse checkout

Run this from the repository root after checking that you are on the intended branch. Review staged, unstaged, and untracked work first; save what you need to keep before changing the scope. The example keeps the app and shared directories and later adds docs. Substitute directories that exist in your repository.

In cone mode, each selected directory is included recursively. Git also keeps tracked files directly at the repository root and directly in each ancestor directory on the way to a selected directory. Selecting services/payments can therefore keep a root build file and services/README.md without pulling the services/inventory directory into the worktree. Root files still appearing is expected.

Use set to replace the selection and add to extend it. Use disable to restore the full worktree when you need it; on a partial clone this may require more downloads. Excluding a tracked path from the worktree does not delete it from the next commit or reclaim the Git objects you already downloaded. This is also not an access boundary: anyone with repository access can request paths outside the selection.

git status --short
git sparse-checkout set --cone app shared
git sparse-checkout list
git sparse-checkout add docs
# When you need the full worktree again:
# git sparse-checkout disable

Source: Git sparse-checkout: cone mode, set, add, disable, and reapply ↗

Fresh clone: defer blobs and narrow the first checkout

For a fresh clone, combine --filter=blob:none and --sparse if the remote supports partial clone. Replace the example URL and directory selection with yours. With --sparse, Git initially populates tracked root files, then the set command expands the selection to the directories you need. A filtered clone with a normal full checkout may still fetch the blobs for all files in the checked-out snapshot immediately.

With blob:none, the initial filtered transfer can include commits and trees while omitting their file contents. Git can ask a promisor remote for a missing object when an operation needs it. This is why a clone can show commit history but later need a connection to show a historical diff. An ordinary sparse checkout of a complete clone does not acquire that dependency just by narrowing the worktree.

Measure the workflow you care about. If most developers immediately open the same large directories or regularly diff old revisions, some cost simply moves from clone time to later operations. If developers need to switch networks or work offline, try their actual commands while disconnected before making a filtered clone the team default. A commit graph can be available offline while content for an older file is missing.

git clone --filter=blob:none --sparse https://example.invalid/team/monorepo.git
cd monorepo
git sparse-checkout set --cone services/payments shared/schemas
git sparse-checkout list
git rev-parse --is-shallow-repository

Source: Git clone: sparse checkout, object filters, and shallow history ↗

Lab: show a missing blob, then fetch it by widening the checkout

Run the Bash block with a recent Git. It builds a disposable repository with two commits and a bare remote that accepts filtering. The file:// URL exercises Git’s transport; passing a local path directly can take a local clone shortcut that does not exercise the filter. The script prints the temporary directory at the end so you can inspect or remove it yourself.

The two clones have the same sparse view of app and both omit docs/guide.txt. The full clone still lists the docs object with its path. The partial clone reports the exact same object ID with a leading question mark, which means the object is missing locally. Git still reports that the clone is not shallow, and the script checks that it has both commits.

After sparse-checkout add docs, Git needs the missing blob to write the file. The script prints the file’s contents and checks that the object now appears with its path. It gets the reference ID from the complete source repository so the check itself does not accidentally retrieve the blob from the partial clone. The experiment demonstrates availability, not a speed or disk savings estimate.

set -eu
lab=$(mktemp -d)
git init -q -b main "$lab/origin"
git -C "$lab/origin" config user.name "Sparse Lab"
git -C "$lab/origin" config user.email "lab@example.invalid"
mkdir -p "$lab/origin/app" "$lab/origin/docs"
printf 'Lab repository\n' > "$lab/origin/README.md"
printf 'app version 1\n' > "$lab/origin/app/main.txt"
printf 'docs are fetched later\n' > "$lab/origin/docs/guide.txt"
git -C "$lab/origin" add .
git -C "$lab/origin" commit -qm "Create lab"
printf 'app version 2\n' > "$lab/origin/app/main.txt"
git -C "$lab/origin" commit -qam "Change app"

git clone -q --bare "$lab/origin" "$lab/remote.git"
git -C "$lab/remote.git" config uploadpack.allowFilter true
remote="file://$lab/remote.git"
docs_blob=$(git -C "$lab/origin" rev-parse HEAD:docs/guide.txt)

git clone -q --sparse "$remote" "$lab/full"
git -C "$lab/full" sparse-checkout set --cone app
git clone -q --filter=blob:none --sparse "$remote" "$lab/partial"
git -C "$lab/partial" sparse-checkout set --cone app

# Both worktrees omit docs, but their object stores differ.
test ! -e "$lab/full/docs/guide.txt"
test ! -e "$lab/partial/docs/guide.txt"
test -f "$lab/partial/README.md"
test -f "$lab/partial/app/main.txt"
git -C "$lab/full" rev-list --objects HEAD --missing=print > "$lab/full.objects"
git -C "$lab/partial" rev-list --objects HEAD --missing=print > "$lab/partial.objects"
grep -Fx "$docs_blob docs/guide.txt" "$lab/full.objects"
grep -Fx "?$docs_blob" "$lab/partial.objects"
git -C "$lab/partial" rev-parse --is-shallow-repository
test "$(git -C "$lab/partial" rev-list --count HEAD)" = 2

# Expanding the worktree makes Git fetch the missing docs blob.
git -C "$lab/partial" sparse-checkout add docs
cat "$lab/partial/docs/guide.txt"
git -C "$lab/partial" rev-list --objects HEAD --missing=print > "$lab/after.objects"
grep -Fx "$docs_blob docs/guide.txt" "$lab/after.objects"
printf 'Lab files: %s\n' "$lab"

Source: Git rev-list: object traversal and missing object reporting ↗

Troubleshoot the symptom before widening the scope

The file is missing from the checkout. Run git ls-tree -r --name-only HEAD -- path/to/file to see whether the current commit tracks it. If the path is listed there, inspect git sparse-checkout list and add the containing directory if you need it. If the tree does not contain the path, changing the sparse selection cannot add it to that commit. Check the branch, filename, or whether it is generated by the build.

The clone command worked, but the transfer was still large. Read the clone output for a message that filtering was ignored or unsupported, and verify support with the repository host. Even with filter support, the checkout and your follow-up commands can download blobs. Compare runs against the same revision and with the same path selection before drawing conclusions from repository size.

A history command fails offline. Check which boundary you are hitting. If git rev-parse --is-shallow-repository prints true, the commits you need may be outside the shallow boundary. If the commit is available but its contents cannot be read, the partial clone may need a blob from the remote. git rev-list --objects HEAD --missing=print reports missing objects without treating them like ordinary readable objects. Limit the walk to a relevant revision; a traversal of a large history can itself take time.

A merge or rebase leaves files outside the selection on disk. Resolve any conflicts and preserve work you intend to keep. Then use git sparse-checkout reapply to restore the selected view where Git can do so. Avoid deleting files or using a hard reset as a general fix for an unexpected worktree; first check whether the files carry changes you need.

The build breaks after narrowing the checkout. A service might use generated code, shared schemas, root tooling, or another package through a relative path. Add the missing directories and run the same build and tests you normally use. If a job routinely needs nearly everything, keeping a full worktree for that job can be simpler than maintaining a long list of exceptions.

Source: Git partial clone: promisor remotes and fetching missing objects ↗

Choose the smallest change that solves the bottleneck

For a long-lived developer checkout that is already downloaded, use sparse checkout when the pain is editor indexing or worktree clutter. For a fresh clone that spends time transferring contents you rarely read, try a filtered sparse clone and measure through the first successful build. For a disposable job that only needs the checked-out revision, consider shallow history separately and test any steps that compare against another branch or derive versions from tags.

Record the required directories and the commands you tested in your team’s setup instructions. A useful rollout check is whether a new teammate can clone, build, and run tests, then expand the selection without guessing why a file was absent. If that works and you can explain which objects may still need a network connection, you have evidence that the narrower setup fits your workflow.

KEEP THESE THREE THINGS

Your next steps

  1. Use sparse checkout for an existing clone when you want fewer paths on disk.
  2. For a fresh clone with filter support, combine --filter=blob:none and --sparse, then test the complete build workflow.
  3. Check object availability and history depth separately when debugging missing files or offline errors.

Sources & official resources

Linked resources checked on 2026-11-08. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →