Sub topic 9
Promisor remotes and how lazy fetching works
This chapter assumes you know how to clone, fetch, and commit, and that you know Git stores commits, trees, and blobs. It also assumes you have seen the --filter option on git clone. Here you will see how a partial clone finds the objects it left behind.
What a promisor remote is
A partial clone leaves some objects out on purpose. Git needs a record that the missing objects are expected and not a sign of corruption. That record is the promisor remote.
A promisor remote is a remote that promises to supply any object the local repository lacks. When you clone with --filter, Git marks origin as a promisor and stores the filter it used. The packfiles from that remote are also tagged as promisor packs. Any object reachable from objects in those packs may be missing without causing an error.
Lazy fetching in practice
When a command needs an object that is not stored locally, Git asks the promisor remote for it. This is called lazy fetching. The command pauses, downloads the object, and then continues.
git clone --filter=blob:none https://example.com/org/big-repo.git
cd big-repo
git log --oneline -- README.md
git show HEAD:README.mdThe clone has all commits and trees, so git log works offline. The git show command needs the blob for README.md at HEAD. Git fetches it from origin and then prints it. A later git show for the same file reads the local copy.
The checkout done by git clone also triggers a fetch, because the files in the working tree need their blobs. Git batches those requests into one fetch.
The sequence of a lazy fetch
Which commands trigger fetches
Commands that read file contents are the usual cause. Examples are checkout, switch, show, diff, blame, and grep over history. Commands that read only commits, such as git log without paths that need diffs, stay local. A path-limited git log in a blobless clone can still need trees, and a treeless clone may fetch those.
Many small on-demand fetches are slower than one large download. A command such as git blame on an old file can trigger many requests in turn.
Inspecting the promisor settings
These commands show whether a repository is a partial clone and which filter it used.
git config --get remote.origin.promisor
git config --get remote.origin.partialclonefilterThe first prints true for a promisor remote. The second prints a value such as blob:none.
You can also list objects that are referenced but absent.
git rev-list --objects --all --missing=print | grep '^?'Missing objects are printed with a leading ?.
Common errors
- Offline failures. With no network, a command that needs a missing blob fails, because the promisor remote cannot be reached. Run the needed commands once while online, or fetch the objects beforehand.
- Unexpected fetches. A tool that scans all files, such as an editor indexer or
git grepacross history, can download everything. Check the settings above, then narrow the tool's scope. - Removed remote. If you delete or rename the promisor remote, Git cannot find missing objects and reports errors. Keep the remote, or restore it with its promisor settings.
Exercise
You cloned with --filter=blob:none, then disconnected from the network. git log --oneline works, but git show HEAD:README.md fails. Why, and how could you have avoided it?
Show answer
git log needs only commits, which were downloaded. git show needs the blob for README.md, which was not downloaded and cannot be fetched from the promisor remote while offline. Run git show HEAD:README.md (or a checkout that includes the file) while online first, so the blob is stored locally.