codient/blog

How partial clones work

I covered how a full git clone works under the hood in part 1 and part 2.

However, for large repos a full clone is slow. For example, a full clone of Git's own repository is 311 MB in size and took 16 seconds to download.

$ git clone https://github.com/git/git
remote: Enumerating objects: 424800, done.
remote: Total 424800 (delta 437), reused 369 (delta 369), pack-reused 424304 (from 2)
Receiving objects: 100% (424800/424800), 310.92 MiB | 53.21 MiB/s, done.

The newest commit (commit, tree, blob) is only 13 MB. The rest is history. In total the clone holds 86,000 commits, 170,000 trees and 167,000 blobs, every version of every file back to 7 April 2005.

Git lets you skip older objects to reduce the size of your clone. In this post, we will look at the three ways to do that and when to use them.

Three ways to do a partial clone

Here's our tiny repo: four commits, 13 objects. Commits point to trees, and trees point to blobs.

The tiny repository
Click any object to see its real hash and what it points to.
Click c4 to start.

A shallow clone (--depth=1) gets the newest commit and its files: c4, its tree and its two blobs.

A blobless clone (--filter=blob:none) gets every commit and every tree, and no blobs.

A treeless clone (--filter=tree:0) gets only the commits.

What each clone gets
The tiny repo's 13 objects. Pick a clone: solid boxes come in the clone's pack, dashed ones stay on the server.
clonetiny repoGit's repo
full13 objects311 MB
blobless8110 MB
treeless434 MB
shallow413 MB

The three ways differ in how much history you get.

Shallow keeps no history. For your machine, the history starts at c4.

Treeless keeps the list of commits: who, when, the message, the parent. It can't tell what changed.

Blobless keeps every tree too. A tree lists each file's name and the hash of its contents. Compare c3's tree with c4's: the readme has the same hash, app.py doesn't. So git knows c4 changed app.py without opening either file.

Check yourself
Which clone gives you c1's commit, but not c1's tree?
In a blobless clone, how does git know c4 changed app.py?

How the server builds the pack file

Before the client asks "what do you have?", it says which version of the protocol it speaks. The server replies with what it can do.

If you run GIT_TRACE_PACKET=1 git clone, you should see output like this:

server> version 2
server> ls-refs=unborn
server> fetch=shallow wait-for-done filter

shallow and filter are the two that matter for partial clones. If a server doesn't list filter, git prints warning: filtering not recognized by server, ignoring and clones everything.

A full clone says want c4, done. Blobless adds filter blob:none. Shallow adds deepen 1, and the server answers shallow c4: your history stops there.

Blobless and treeless

In part 1, the server found c4's objects by reading its bitmap. That's a row with one box per object in the server's stored pack, and a 1 means c4 needs it.

The same bitmap file has one more row per kind of object. It marks which positions are commits, which are trees and which are blobs.

A filter, as bitmap rows
c4's row says what c4 needs. The rows under it, saved in the same file, say what kind each object is. Pick a clone.

For a blobless clone, the server takes c4's row and crosses out every blob. 8 objects are left. It can do this without having to walk the history graph. It copies them byte for byte from the stored pack, like a full clone. Treeless crosses out the trees too.

On Git's repo, 256,880 of the 257,323 objects came straight from the stored pack:

remote: Enumerating objects: 257323, done.
remote: Total 257323 (delta 405), reused 349 (delta 349), pack-reused 256880 (from 2)

Shallow: build it by hand

A shallow clone can't use bitmaps. c4's row means c4 and everything before it. No row means c4 alone.

So the server opens c4, opens its tree, collects the files and stops. Then it builds a new pack, one object at a time:

remote: Enumerating objects: 4980, done.
remote: Counting objects: 100% (4980/4980), done.
remote: Compressing objects: 100% (4365/4365), done.
remote: Total 4980 (delta 500), reused 2183 (delta 444), pack-reused 0 (from 0)

Counting looks up each object. Compressing is the delta search from part 2. pack-reused 0 means nothing was copied.

On a local copy of Git's repo that took about half a second, because there's so little to send. The server redoes it for every shallow clone.

Check yourself
Why can a blobless clone skip the walk, but a shallow clone can't?

After the clone

Checkout

Git clone does one more thing that parts 1 and 2 skipped. It writes the newest commit's files into your folder.

Resolving deltas: 100% (166855/166855), done.
Updating files: 100% (4875/4875), done.

In a blobless clone, git opens c4, then c4's tree, and looks for the two files' hashes. Neither is there. Git asks the server for them by hash. Step through it:

Checkout, in a partial clone
What's on your machine after the clone. Step through checkout and watch what git asks the server for.
trips to the server: 0

On Git's repo, checkout fetched 4,758 blobs in one trip. It never downloaded the 162,700 older ones. You only download an old version when you open it.

Treeless is the same, one level up. Git can't know the files' hashes until it has the tree. So you need two trips (first to fetch the tree and then the blobs).

Comparing the different types of clones

Let's compare the following use cases against the different types of clones (full, treeless, blobless, shallow):

Same job, four clones
An agent fixing a bug in Express. Run each step in all four clones, then click a row to see what happened.

Searching and pushing work the same for all 4 types of clones. History is where the four differ.

History of one file

Full and blobless are instant, because the trees say which commits changed the file. Treeless has no trees, so it fetches them one commit at a time.

Shallow is instant and wrong. It says the last change to lib/application.js was a dependency bump that never touched it:

$ git log -5 --oneline -- lib/application.js # shallow
43fca52 deps: body-parser@^2.4.0 (#7563)

That's the commit where history was cut, so every file looks like it was added there. The full clone shows four real changes, starting with 90ec6206, "Improve error logging by logging full error object".

Blame

Blame needs every old version of the file, and it only learns which one it needs next after reading the last. So it asks one at a time. -L 1,30 doesn't help, because it limits what's printed, not what git reads.

Shallow puts every line on one commit:

$ git blame -L 1,2 lib/application.js # shallow
^43fca52 (Lazizbek Ergashev 2026-11-03 01:15:26 +0500 1) /*!
^43fca52 (Lazizbek Ergashev 2026-11-03 01:15:26 +0500 2) * express
$ git blame -L 1,1 lib/application.js # full
b40e74d6b (Douglas Christopher Wilson 2015-02-18 00:59:56 -0500 1) /*!
Check yourself
Why does blame on a blobless clone take one trip per old version?
What's the only sign that blame on a shallow clone is wrong?

When to use which

Working in a repo yourself: blobless. You get all of history without any of the old files.

CI: shallow clone. Or treeless, if the build needs the commit list.

Coding agent: blobless. Agents read history quite often.