Sub topic 2
Deepening History and Converting to a Full Clone
Assume you know clone, fetch, branches, and commits, and understand that Git stores file contents as blobs. This chapter shows how to extend a shallow clone, then explains how partial clones download objects on demand.
Deepen or Remove the Shallow Boundary
A shallow clone contains only recent history. Git marks the oldest included commits in .git/shallow. Commands that need older ancestors may stop at that boundary.
Use --deepen when you need a limited amount of additional history:
git fetch --deepen 50
git log --oneline --allThis downloads enough history to add 50 commits where possible. The repository remains shallow.
Use --unshallow when you need the complete reachable history:
git fetch --unshallow
git rev-parse --is-shallow-repositoryThe final command prints false after the conversion. These operations can download a large amount of data, especially when many branches or tags are involved.
Partial Clones and Object Filters
A partial clone downloads only some Git objects at first. Git records the remote as a promisor remote, meaning the remote promises to provide omitted objects later.
The blob:none filter omits file contents while keeping commits and directory trees:
git clone --filter=blob:none https://example.com/org/big-repo.git
cd big-repo
git log --oneline
git show HEAD:README.mdgit log can work locally because commits are present. git show may trigger a fetch for the missing README.md blob.
Choosing a Filter
| Filter | Initially omits | Typical use |
|---|---|---|
| `blob:none` | All file contents | History inspection and broad development |
| `blob:limit=1048576` | Blobs larger than 1 MiB | Keep small files local |
| `tree:0` | Trees and blobs until needed | Fast current-snapshot or CI clones |
A treeless clone often works well with a shallow clone:
git clone --filter=tree:0 --depth 1 https://example.com/org/big-repo.gitLazy Fetching and Its Costs
When a command needs an omitted object, Git contacts the promisor remote and stores the object locally. Later commands can reuse it. This is called lazy fetching.
Unexpected network access can slow commands or fail offline. Inspect the configuration with:
git config --get remote.origin.promisor
git config --get remote.origin.partialclonefilterExercise
Which command converts a shallow repository into a full clone?
Show answer
git fetch --unshallow.