How the sparse clone actually works
1. Deferring file contents: --filter=blob:none
A git repo's history is built from three kinds of objects: commits, trees, and blobs. Trees are directory listings — the name, type, and hash of every entry — and blobs are the actual file contents. A normal clone downloads all three, for every commit in the history you fetch.
--filter=blob:none tells the server to send commits and trees as normal — so you get full history and know every filename that ever existed — but to hold back blobs. Git fetches a blob's content lazily, the moment it actually needs to put that file on disk.
2. Getting an exact folder match: --no-cone
This is the part that's easy to get wrong. Git's default sparse-checkout mode — "cone mode" — does not give you just the folder you ask for. If you run the more commonly documented git sparse-checkout set some/folder in cone mode, git also checks out:
- every file at the root of the repository, and
- the immediate files of every directory on the path down to your folder.
Cone mode is built that way on purpose — it's meant for "give me the normal top-level view, plus a deep dive into a couple of subprojects," which is a common monorepo pattern, and it's faster for git to evaluate at scale. But it means the checkout isn't exact.
--no-cone switches to plain pattern matching instead, so we can hand git one explicit pattern — /samples/rust/** — meaning "everything under this path, recursively, and nothing else." No root files, no sibling directories.
3. Why git checkout only downloads what you asked for
Once the sparse-checkout pattern is set, running git checkout walks the target commit's tree (already local, since trees aren't filtered), compares it against the pattern, and only materializes — and therefore only fetches the blob content for — the entries that match. Everything outside the pattern stays as a tree reference only: git knows it exists, but never asks the server for its content.
What you still get "for free"
Because trees and commits were never filtered, you keep full commit history for the whole repository — git log, git blame, and browsing past revisions all work normally on the files you do have. And since nothing was permanently discarded, you can always expand later with git sparse-checkout disable — git just fetches the additional blobs it's now missing, on demand, without a re-clone.