Sub topic 12
Server and hosting requirements for filtered clones
This chapter assumes you know how to run git clone, git fetch, and git config. It also assumes you know that Git stores commits, trees, and blobs, and that you have seen --filter used in an earlier chapter. Here you will learn what the remote must support for filtered clones to work and how to check it.
Why the server matters
A shallow clone and a partial clone differ in who does the work. With --depth, the server walks history and stops early. With --filter, the server must also leave objects out of the pack it sends and later answer requests for individual missing objects.
Not every server does this. A filter needs the server to advertise the filter capability in protocol v2. Servers that do not advertise it cannot honor the request.
What the server must provide
- It must speak Git protocol v2, or the older protocol with the filter capability enabled.
- It must allow filtering. For a self-hosted server, the setting is
uploadpack.allowFilter. - It must allow clients to request objects by ID. The related settings are
uploadpack.allowAnySHA1InWantanduploadpack.allowReachableSHA1InWant. Lazy fetching depends on this, because the client asks for blobs by hash.
On a self-hosted bare repository, you can enable these settings like this:
git config uploadpack.allowFilter true
git config uploadpack.allowAnySHA1InWant trueMajor hosting services such as GitHub, GitLab, Bitbucket, and Azure DevOps support filtered clones on their hosted repositories. Older self-managed installations, dumb HTTP servers, and some proxies may not. Check the product's documentation for the version you run.
What happens when the server refuses
If the server does not support filters, the client usually prints a warning and carries on with a full clone. This can be easy to miss.
git clone --filter=blob:none https://example.com/org/big-repo.gitA typical result is a warning such as warning: filtering not recognized by server, ignoring. The clone succeeds, but it downloads everything. Always confirm the result instead of assuming it worked.
cd big-repo
git config --get remote.origin.promisor
git config --get remote.origin.partialclonefilterIf both commands print nothing, the repository is not a partial clone. If the first prints true and the second prints blob:none, the filter was accepted.
Where the requests go
Practical consequences
Lazy fetching means the remote must stay reachable. If you go offline, or the remote is moved or deleted, commands that need a missing blob fail. A partial clone is not a full backup of the repository.
Each on-demand fetch is a separate round trip. A command that touches many missing objects, such as git blame on a large file, can trigger many requests. Some servers rate-limit these. Corporate proxies that rewrite or cache Git traffic can also break the object-by-ID requests.
Shallow clones need less from the server. Almost all Git servers support --depth, so you can usually fall back to it when filters are not available.
Checking support before you depend on it
Ask the remote what it advertises before you build a pipeline on it:
git -c protocol.version=2 ls-remote --heads https://example.com/org/big-repo.git
GIT_TRACE_PACKET=1 git -c protocol.version=2 ls-remote https://example.com/org/big-repo.git 2>&1 | grep -i filterIf the trace output contains filter among the capabilities, the server supports it. No match means filters are not available, and you should plan on --depth instead.
Exercise
You run git clone --filter=blob:none against an internal server. The clone finishes, but git config --get remote.origin.promisor prints nothing. What most likely happened, and what should you check on the server?
Show answer
The server did not accept the filter and Git fell back to a full clone, so the repository is not a partial clone. Check that the server runs protocol v2 and that uploadpack.allowFilter is set to true. Also check that any proxy in between passes the filter request through.