Sub topic 8
Choosing a filter: blob:none, blob:limit, and tree:0
This chapter assumes you know how to clone and fetch, and that Git stores history as commits, trees (directory listings), and blobs (file contents). A partial clone uses a filter to leave some of those objects out of the initial download. Your choice of filter decides what you download up front and what Git fetches later.
What each filter omits
The filter is set with --filter=<spec> on git clone. Three specs cover most needs.
| Filter | Downloaded at clone time | Left out | Typical use |
|---|---|---|---|
| `blob:none` | All commits and trees, plus blobs needed for the checkout | Every other blob | Daily development |
| `blob:limit=1m` | Commits, trees, and blobs under 1 MiB | Blobs of 1 MiB or more | Repositories with a few huge binaries |
| `tree:0` | Commits only, plus what the checkout needs | All other trees and blobs | Build jobs that need only the current snapshot |
The checkout itself still needs the files for the branch tip, so those blobs are always fetched. A filter only affects the objects that the checkout does not need.
blob:none
A blobless clone keeps the full commit and tree graph. Commands that read only history, such as git log or git branch --contains, work offline. Commands that read file contents, such as git show on an old revision or git blame, may trigger a fetch.
git clone --filter=blob:none https://example.com/org/big-repo.git
cd big-repo
git log --oneline -- README.md
git show HEAD:README.mdPath-limited git log works without blobs because Git compares tree entries. Showing a diff needs blob contents, so Git fetches the missing ones.
blob:limit
blob:limit=<size> is a middle path. It downloads small blobs, which are cheap and common, and defers large ones. The size accepts the suffixes k, m, and g.
git clone --filter=blob:limit=1m https://example.com/org/big-repo.gitThis works well when most of the repository's weight sits in a handful of large files, such as compiled assets or datasets. Source files stay local, so most commands never fetch anything.
tree:0
A treeless clone downloads commits only. Trees and blobs arrive when a command needs them. Any command that walks a directory structure triggers fetches, so history browsing is slower than with blob:none.
git clone --filter=tree:0 --depth 1 https://example.com/org/big-repo.gitCombined with --depth 1, this gives the smallest practical download for a job that reads only the current files.
Common errors
- Surprise fetches. Running
git blameorgit log -pon a blobless clone fetches many blobs one batch at a time. Run these on a clone that has the data, or accept the delay. - Treeless clones in daily work.
git checkoutof another branch, orgit merge, may need many trees. For development,blob:noneis usually the better trade. - Filter ignored. If the server does not support filtering, Git warns that the filter was ignored and downloads everything. Check the output of the clone.
Exercise
A repository has 4 GB of history, most of it in a few 200 MB video files. Developers need full history for git log and git blame on source files. Which filter fits, and why?
Show answer
--filter=blob:limit=1m (or a similar small limit). It keeps all source blobs locally, so git blame on source files does not trigger fetches, while the large video blobs are deferred. blob:none would also work but would fetch source blobs on demand during blame, and tree:0 would make history browsing slow.