Sub topic 15
Inspecting and Troubleshooting Shallow and Partial Repositories
This chapter assumes you know basic Git (clone, fetch, branch) and have read the earlier chapters on shallow clones, partial clones, and sparse checkout. Here you will learn to tell what kind of repository you have and to fix the common problems.
Inspect before you fix
Most problems come from not knowing how a repository was cloned. These commands tell you.
git rev-parse --is-shallow-repository
git config --get remote.origin.promisor
git config --get remote.origin.partialclonefilter
git sparse-checkout listThe first command prints true for a shallow repository. The second prints true when origin is a promisor remote, which means Git may fetch missing objects from it later. The third prints the filter, such as blob:none. The last lists the sparse-checkout paths. A command that prints nothing usually means that feature is not in use.
For a shallow repository, the file .git/shallow lists the commits where history is cut off.
Common problems
Missing history
Symptoms include git log stopping early, a merge base that cannot be found, or a tool reporting an unknown revision. The repository is shallow, and the commit you need is beyond the cut-off. Deepen it or convert it:
git fetch --deepen 50
git fetch --unshallowUse --deepen first. Run --unshallow only when you need everything.
Unexpected on-demand fetches
In a partial clone, a command that needs a missing object makes Git contact the remote. This is why git blame, git log -p, or git diff across old commits can be slow in a blobless clone. Each one may download many blobs.
To find the cause, check the filter and the sparse paths:
git config --get remote.origin.partialclonefilter
git sparse-checkout listIf the sparse list is empty or wide, a checkout downloads many blobs. Narrow it with git sparse-checkout set. If you often run history-heavy commands, a blobless clone may be the wrong choice, and a full clone may suit you better.
Offline failures
A partial clone is not fully offline. If the network is down, any command that needs a missing blob fails. Commands that use only commits and trees, such as git log --oneline, still work in a blobless clone.
Servers that reject filters
If the server does not support filtering, git clone --filter=... prints a warning that the filter is not supported and downloads everything, or it fails. Confirm the server allows filters, then fall back to --depth 1 if it does not.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| `git log` stops early | Shallow clone | `git fetch --deepen N` |
| Merge base not found | History cut off | `git fetch --unshallow` |
| Slow `git blame` | Blobs fetched on demand | Use a full clone or narrow the range |
| Large download at checkout | Wide sparse paths | `git sparse-checkout set` with fewer paths |
| Filter ignored or rejected | Server lacks support | Use `--depth` instead |
Exercise
A teammate's blobless clone is slow when they run git log -p over a year of history, even though the clone itself was fast. Why does this happen, and which command confirms the clone type?
Show answer
git log -p needs the file contents of each commit, and a blobless clone does not store them. Git fetches the missing blobs from the promisor remote on demand, which is slow over many commits. git config --get remote.origin.partialclonefilter prints blob:none and confirms the clone type.
Exercise
A CI job cloned with --depth 1 fails because a tool cannot find the merge base with main. What is the smallest fix?
Show answer
Run git fetch --deepen N with enough commits to reach the merge base, instead of git fetch --unshallow, which downloads all history.