How to update a git shallow clone?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
A shallow clone can be updated normally, but you need to remember that its history is intentionally incomplete. Depending on what you need, updating may mean fetching the latest commits at the same shallow depth, deepening the history, or converting the clone into a full repository.
What a Shallow Clone Is
A shallow clone is created with a limited history, for example:
That gives you the newest visible snapshot plus only a small amount of commit history. It is useful for CI, large repositories, and quick read-only work, but it affects operations that need ancestry information.
Update the Latest History at the Current Depth
If you simply want the newest commits while remaining shallow, fetch and then fast-forward:
For many workflows, that is enough. Git keeps the repository shallow and updates the checked-out branch to the latest reachable commit.
If you want to be explicit about depth:
This is common in automation where only the latest state matters.
Deepen the Clone
If the shallow history is too short for a merge, rebase, blame, or log operation, fetch more history without going fully deep:
That adds 50 more commits of history behind the current shallow boundary.
You can also fetch to an absolute depth:
Use --deepen when you want to extend what you already have incrementally. Use --depth when you want the shallow history reset to a specific total depth.
Convert to a Full Clone
If the shallow restriction is now getting in the way, unshallow the repository:
After that, the clone behaves like a normal full clone and operations that depend on complete history become much more reliable.
This is often the right move when a shallow clone started as a CI optimization but the local work has evolved into real development.
Fetch Tags and Other Refs Carefully
Shallow clones often omit history and sometimes tags that older commits reference. If you need tags too:
Just remember that tag usefulness can still be limited if the associated commit history has not been fetched yet.
Likewise, if you need another branch, fetch that branch explicitly:
Shallow clones are more explicit by nature. You do not always have the historical context for every branch unless you fetch it.
Why Some Operations Fail in Shallow Clones
Commands that need ancestry beyond the shallow boundary can misbehave or stop with errors. Common examples include:
- rebasing onto older history
- merge-base calculations
- some blame and bisect workflows
- scripts that assume full repository history
When this happens, the fix is usually not a special flag on the failing command. The fix is to fetch enough history for the command to make sense.
A Practical Update Sequence
A good decision flow is:
- if you just need the newest snapshot, run
git fetchandgit pull --ff-only - if history-dependent commands fail, use
--deepen - if the repo has effectively become a development clone, use
--unshallow
That is cleaner than guessing blindly at depth values every time a command breaks.
Common Pitfalls
- Assuming a shallow clone updates differently from a normal clone for basic fetch and pull operations. The difference usually appears only when history depth matters.
- Using
git pullblindly when the local branch cannot fast-forward cleanly and the missing history makes troubleshooting harder. - Forgetting that rebases, merge-base logic, and history inspection often need more than a depth-1 clone can provide.
- Repeatedly increasing depth by trial and error when the real solution is simply
git fetch --unshallow. - Assuming tags or other branches are fully useful in a shallow clone without fetching the necessary related history.
Summary
- A shallow clone can be updated with normal
fetchandpullcommands. - Use
--deepenor--depthwhen you need more history but still want to stay shallow. - Use
--unshallowwhen the repository should become a normal full clone. - Many shallow-clone problems are really history-availability problems, not update-command problems.
- Choose the smallest history that supports your actual workflow, then deepen only when needed.
Related reading
- How to update a pull request from forked repo?
- How to update git commit author, but keep original date when amending?
- How to update local tags to match remote?
- How to upgrade Git on Windows to the latest version
- How to upgrade Git on Windows to the latest version
- How to upgrade Git to latest version on macOS?
- How to use Git and Dropbox together?
- How to use Git and Dropbox together?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.