Sub topic 12
Server and Hosting Requirements for Filtered Clones
This chapter assumes you can run git clone, git fetch, and git config. It also assumes you know what --depth and --filter=blob:none do from earlier chapters. Here you learn what the server must support for those options to work, how to check support, and what happens when support is missing.
Why the server matters
A shallow or partial clone is a negotiation. The client asks for fewer objects, and the server decides whether it will build a smaller pack. Git cannot do this work on the client side alone.
Two features differ in how much they depend on the server:
- Shallow clones (
--depth) need the server to understand shallow requests. Every modern smart-protocol server does. - Filtered clones (
--filter=...) need the server to accept an object filter. This is opt-in on self-hosted servers, and some hosts or proxies do not offer it.
A filtered clone also keeps depending on the server after the clone finishes. The client records the remote as a promisor remote. Later commands fetch missing objects from it on demand, so the server must stay reachable and must answer requests for individual objects.
What a server must provide
For a filtered clone, the server must meet these requirements:
| Requirement | Why it is needed |
|---|---|
| A smart transport (SSH, `git://`, or smart HTTP) | Filters and shallow requests are part of the fetch protocol. |
| `uploadpack.allowFilter` set to `true` | Without it, `git upload-pack` ignores filter requests. |
| Protocol version 2, or a server that accepts wants for individual object IDs | Lazy fetching asks for specific missing blobs and trees by ID. |
| Stable, authenticated access after the clone | Later checkouts, `git show`, and `git diff` may need to contact the remote. |
Git has used protocol version 2 by default since 2.26. Most hosted services and current Git servers handle all of the above. Problems usually come from three sources: an old self-hosted server, a mirror or proxy that strips the capability, and a dumb HTTP server.
A dumb HTTP server serves static files and cannot take part in the fetch negotiation. Neither --depth nor --filter works against it.
Enabling filters on a self-hosted server
On a server you control, set the option in the bare repository, or globally for all repositories on the host:
git --git-dir=/srv/git/big-repo.git config uploadpack.allowFilter trueYou can also set it for every repository the server user owns:
git config --global uploadpack.allowFilter trueSome setups also set uploadpack.allowAnySHA1InWant true. It lets clients ask for any object by ID, which older protocol versions otherwise restrict. Treat it as a security decision. It allows a client to request an object that is no longer reachable from any ref, for example after a force push removed a leaked secret. Only enable it if your Git version needs it for lazy fetching and you accept that exposure.
Checking support before you rely on it
You can inspect what a remote advertises. With protocol version 2, the server lists a fetch= capability, and filter appears in it when filters are enabled:
GIT_TRACE_PACKET=1 git -c protocol.version=2 ls-remote origin 2>&1 | grep 'fetch='A server that supports both features prints a line like fetch=shallow wait-for-done filter. If filter is missing, a filtered clone will not work against that server.
A local experiment
You can reproduce both outcomes on your own machine without a hosting service. The script below builds a small repository, serves it as a bare clone, and tries a filtered clone before and after enabling the option. It uses a file:// URL because Git treats a plain local path as a local copy and ignores --depth and --filter for it.
set -e
rm -rf demo && mkdir demo && cd demo
git init -q -b main work
cd work
echo hello > a.txt
git add a.txt
git -c user.name=t -c [email protected] commit -qm "first"
echo more > b.txt
git add b.txt
git -c user.name=t -c [email protected] commit -qm "second"
cd ..
git clone -q --bare work server.git
echo "--- before enabling the filter ---"
git clone --filter=blob:none "file://$PWD/server.git" client1
git -C client1 config --get remote.origin.promisor || echo "not a partial clone"
echo "--- after enabling the filter ---"
git -C server.git config uploadpack.allowFilter true
git clone --filter=blob:none "file://$PWD/server.git" client2
git -C client2 config --get remote.origin.promisor
git -C client2 config --get remote.origin.partialclonefilterThe first clone prints warning: filtering not recognized by server, ignoring and succeeds as a full clone. The second clone is partial. It prints true for the promisor setting and blob:none for the filter.
What happens when a server rejects filters
The behavior depends on how the server fails, and the difference matters in automation.
- The server does not advertise
filter. Git printswarning: filtering not recognized by server, ignoringand carries on with a full clone. The command exits with status 0. A CI job may then download far more than you planned, and nothing fails. - The server advertises
filterbut rejects the specific filter. The fetch fails with an error from the remote. Some servers allowblob:nonebut notblob:limit, or the reverse. - The server accepts the clone but later refuses an on-demand fetch. A command such as
git checkoutorgit showfails while it tries to fetch a missing object.
How a lazy fetch reaches the server
The second request is where problems appear. It happens in the middle of an ordinary command, so a failure looks like a broken checkout or diff instead of a network error. The remote URL must still be valid, the credentials must still work, and the server must accept the request for a bare object ID.
Hosting service considerations
Major hosting services such as GitHub and GitLab support filtered clones. Support varies in the details, so check your provider's documentation for the exact filter specs it allows, including tree:0 and blob:limit. Do not assume all of them are accepted.
Other points to check in a hosted or corporate setup:
- Mirrors and caches. A mirror built from an older Git version, or a caching proxy in front of the server, may not pass filter requests through. Clone from the same URL your developers and CI will use, not from a different one.
- Rate limits. Many on-demand fetches create many small requests. A busy CI fleet can hit request limits that a single large clone would not.
- Server load. A filtered clone moves work to the server. It must compute which objects to send and may need a fresh pack instead of a prebuilt one. Reachability bitmaps help the server answer common filters quickly, so large self-hosted servers benefit from running
git gcwith bitmaps enabled regularly. - Credentials. Short-lived tokens suit a one-time full clone, but a partial clone keeps using the remote afterward. If the token expires before a later lazy fetch, the command fails. Store credentials in a helper, or keep the remote configured the same way your workflow expects.
- Offline use. A partial clone cannot show file contents it never downloaded. Laptops that work offline need those blobs fetched in advance, for example with
git fetch --refetchor by checking out the needed paths first.
A short decision checklist
Before you adopt a filtered clone in a pipeline or team workflow:
- Run the packet trace command and confirm
filterappears infetch=. - Do a trial clone from the exact URL your jobs will use.
- Confirm
remote.origin.promisoristrueafterward. - Check that the credentials in use remain valid after the clone ends.
- Decide what the job should do if the filter is ignored. Fail the build, or accept a full clone.
Exercise
A CI job runs git clone --filter=blob:none https://git.internal.example/org/repo.git and succeeds, but the job now takes as long as before and downloads the whole history with file contents. The job log shows no error. What is the most likely cause, and how can you confirm it?
Show answer
The server or a proxy in front of it does not advertise the filter capability, so Git printed warning: filtering not recognized by server, ignoring and did a full clone with exit status 0. Confirm it by searching the job log for that warning, by running git config --get remote.origin.promisor in the clone (an empty result means it is not partial), or by checking GIT_TRACE_PACKET=1 git -c protocol.version=2 ls-remote origin 2>&1 | grep 'fetch=' for the word filter. The fix on a self-hosted server is git config uploadpack.allowFilter true. If a proxy is the cause, point the job at a URL that passes filter requests through.