Sub topic 9
Promisor Remotes and How Lazy Fetching Works
This chapter assumes you can clone, fetch, and branch in Git. It also assumes you know that Git stores commits, trees, and blobs, and that you have seen --filter=blob:none in an earlier chapter. Here you will learn the mechanism behind partial clones: the promisor remote. You will also learn when it triggers network requests and how to stop surprises.
The idea: a remote that promises the missing objects
A normal clone has every object reachable from the refs it fetched. If Git needs an object, it is on disk, and a missing object means the repository is corrupt.
A partial clone breaks that rule on purpose. The clone leaves out some objects, such as blobs or trees, and Git has to tolerate that. It does so by marking one remote as a promisor remote. A promisor remote is a remote that has promised to supply any object that is missing locally, whenever Git asks for it later.
Three pieces make this work:
- A config entry,
remote.<name>.promisor = true, which marks the remote as a promisor. - A config entry,
remote.<name>.partialclonefilter, which records the filter used (for exampleblob:none). - Promisor packfiles, which are packfiles stored with a
.promisormarker file next to them. The marker tells Git that objects missing from the repository's object graph may be found on the promisor remote.
When Git walks history and finds a reference to an object it does not have, it checks whether that object could come from a promisor pack. If it could, Git treats the object as "promised" and carries on. It only reports corruption if the object is missing and no promise covers it.
Seeing the promise in a real clone
Create a blobless clone and inspect it:
git clone --filter=blob:none https://example.com/org/big-repo.git
cd big-repo
git config --get remote.origin.promisor
git config --get remote.origin.partialclonefilterThe first command prints true. The second prints blob:none. Git also sets extensions.partialClone in the repository config. That extension makes older Git versions refuse to work in the repository instead of misreading it.
You can list the promised objects that are still absent. This command prints the ID of every object that history refers to but that is not stored locally:
git rev-list --objects --all --missing=print | grep '^?'Missing objects appear with a leading ?. In a fresh blobless clone, you will see one line for each blob that is not checked out.
When lazy fetching happens
Git fetches a missing object when a command needs its contents. The fetch is a small request to the promisor remote for just those object IDs. Git stores the result in a new promisor pack, so later commands find it locally.
Here is how common commands behave in a blobless clone.
| Command | Needs blob contents? | Network request? |
|---|---|---|
| `git log`, `git log --oneline` | No | No |
| `git log -- path` | No (trees are enough) | No |
| `git log -p` | Yes, for every commit shown | Yes, possibly many |
| `git show HEAD:README.md` | Yes, one blob | Yes, if not cached |
| `git checkout <branch>` | Yes, for files that change | Yes, one batch |
| `git blame file` | Yes, for each version of the file | Yes, often many |
| `git diff A B` | Yes, for changed files | Yes, one batch |
| `git grep` in the working tree | Only for checked-out files | No |
| `git grep <rev>` | Yes, for the whole tree | Yes, very large |
The key point is that history and tree structure stay offline, but content does not. A git log --oneline on a blobless clone is as fast as on a full clone. A git log -p over 10,000 commits can issue thousands of requests.
Batching
Git tries to group missing objects into one request. git checkout collects all the blobs it needs and asks for them together. Commands that discover missing objects one at a time, such as git blame or a git log -p walk, can fall back to one request per object. Recent Git versions batch more of these cases, but you should not depend on that. Each request costs a round trip, so latency matters. On a slow link a command that looks local can take minutes.
Treeless clones go further
With --filter=tree:0, the clone also omits trees. Now even git log -- path needs trees to decide whether a commit touched the path, so it triggers fetches. A treeless clone is the smallest start, but it pushes the most work to the lazy-fetch path. It suits a build that needs only the current snapshot.
git clone --filter=tree:0 --depth 1 https://example.com/org/big-repo.gitA timeline of one lazy fetch
The following diagram shows what happens when you run git show HEAD~5:src/app.py in a blobless clone where the blob is absent.
The second time you run the same command, the blob is in the local store and no request is sent.
Controlling and observing lazy fetches
Lazy fetching is automatic, which makes accidental downloads easy. Several tools help.
Turn it off to find offenders. Set the environment variable GIT_NO_LAZY_FETCH=1 (available in Git 2.44 and later). Any command that needs a missing object then fails instead of reaching the network. This is a good way to check that a script stays offline.
GIT_NO_LAZY_FETCH=1 git log --oneline -- README.md
GIT_NO_LAZY_FETCH=1 git show HEAD:README.mdThe first command should succeed. The second fails if the blob is not already local, and the error names the missing object.
Watch the traffic. Setting GIT_TRACE=1 prints a line each time Git starts a subprocess. Lazy fetches show up as git fetch calls with --filter=blob:none or similar arguments that you did not type.
Prefetch deliberately. If you know you will need many blobs, fetch them in one request instead of letting Git trickle them in. For example, you can list the missing objects and pass them to git fetch:
git rev-list --objects --missing=print HEAD~100..HEAD | grep '^?' | cut -c2- > wanted.txt
git fetch origin --no-tags --stdin < wanted.txtBecause origin is a promisor remote, the object IDs read from standard input are fetched as one batch. Check that your server allows fetching by object ID, as the next section explains.
Requirements and limits of the promise
The promise is only as good as the server.
- The server must support filters. If it does not,
git clone --filterprints a warning that the filter was ignored and the server sent everything. You get a full clone. - The server must allow fetching arbitrary objects by ID. Lazy fetch asks for objects by ID, not by ref. Servers that disable
uploadpack.allowAnySHA1InWantorallowFilterbreak this. Major hosting services enable it. Self-hosted servers needuploadpack.allowFilter = trueand oftenuploadpack.allowAnySHA1InWant = true. - The promise can break. If the remote deletes objects, for example after a force push followed by garbage collection of unreachable commits, a local reference to those objects can no longer be satisfied. Git then fails with a message like
could not fetch <id> from promisor remote. - Offline work is limited. A blobless clone is fully usable offline only for commands that need no blob contents, and for any blobs already fetched.
Also note that only one promisor remote is common, but Git permits several. If you add a second remote and mark it as a promisor, Git tries each promisor in turn for a missing object.
Common errors
- Slow
git blameorgit log -p. Cause: thousands of single-object fetches. Fix: use a full or shallow clone for that job, or prefetch the blobs in one request. - "Filtering not recognized by server, ignoring." Cause: the server lacks filter support. Fix: use
--depthand sparse checkout instead, or ask the host to enable filters. - Fetch errors during an offline trip. Cause: a command needed a blob you never downloaded. Fix: before going offline, run the commands you need, or run
git checkouton the relevant branches while connected. - Scripts that hang in CI. Cause: a hidden lazy fetch that waits on credentials. Fix: provide credentials to the job, or run the script with
GIT_NO_LAZY_FETCH=1to make the failure explicit. - Surprise downloads after
git gc. Git keeps promisor packs separate and does not delete promised objects it cannot recover. Dropped local copies of fetched blobs, however, are fetched again on the next need.
Check your understanding
Exercise
You run git clone --filter=blob:none on a repository. A teammate runs git log -p over the last 2,000 commits and reports that it takes several minutes, although git log --oneline was instant. Explain why, and name two ways to avoid the delay.
Show answer
git log --oneline reads only commits, which the blobless clone already holds. git log -p must print the diff for every commit, and a diff needs blob contents, which the clone omitted. Git asks the promisor remote for the missing blobs, often one request at a time, so network latency adds up across thousands of objects. To avoid it, prefetch the blobs in one batch with git fetch and a list of object IDs, or use a full clone (or git fetch --refetch after removing the filter) for history-heavy work. Running the command with GIT_NO_LAZY_FETCH=1 would not speed it up, but would show immediately that it needs the network.
Exercise
Which two config keys let you confirm that a repository is a partial clone and see its filter?
Show answer
remote.origin.promisor, which prints true, and remote.origin.partialclonefilter, which prints the filter spec such as blob:none. Read them with git config --get.