Shallow and Partial Clones: History versus Objects
Two independent dimensions
For a project with three commits A, B, C, a depth-one clone of main usually has only C in its traversable history but still needs its checkout files. A blob-filtered partial clone can preserve all three commits while initially omitting file contents. A blob is Git’s stored file-content object; commit and tree objects describe history and paths. The two options can be combined but solve different costs.
Inspect shallow history
In the supplied local fixture, use a file URL to exercise normal Git transport rather than local hardlink cloning. The depth-one clone returns true and 1 for these checks. Fetching complete history from the fixture origin changes those results to false and 3. Tags and other branches may require separate fetches; do not assume every ref exists locally.
git rev-parse --is-shallow-repositorygit rev-list --count HEADgit fetch --unshallow origingit rev-list --count HEADDeferred object retrieval
A server must support filtering. In our fixture only, uploadpack.allowFilter and uploadpack.allowAnySHA1InWant are enabled on the source. The latter is deliberately confined to an isolated training repository, not a production recommendation. --no-checkout avoids immediately fetching the blobs needed to populate the worktree. A promisor remote is a configured source expected to provide omitted objects when requested. Inspect missing objects before requesting a file; reading it may trigger a fetch. The fixture verifies that one requested blob becomes available while other blobs remain absent.
git rev-parse --is-shallow-repositorygit config --get remote.origin.promisorgit rev-list --objects --missing=print HEADgit show HEAD:apps/worker/worker.txtgit rev-list --objects --missing=print HEADChoose according to the task
A quick CI snapshot can benefit from depth limits, but ancestry, tags and bisect may require more history. A developer who needs broad history but few files may prefer partial clone and sparse checkout. Offline work requires that necessary objects are already present. Measure initial transfer, later requests and actual task latency; the tiny local fixture is not a performance benchmark.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Shallow and Partial Clones: History versus Objects — knowledge check
Distinguish storage, history, working tree and maintenance costs.
What does --depth=1 limit?
What does blob:none request?
Why add --no-checkout in the experiment?
What is a promisor remote?
What could fail offline in a partial clone?