BeginnerPhone
1 min
Git Shallow Clone
GitVersion ControlBuild Systems
Advertisement
Interview Question
What does a shallow clone do in Git and when is it useful?
Key Points to Cover
- `git clone --depth N` fetches limited history
- Saves time/bandwidth in CI or large repos
- Trade-off: limited history for bisect/annotate
Evaluation Rubric
Defines shallow clone correctly40% weight
Explains speed/bandwidth benefits30% weight
Mentions history limitations30% weight
Hints
- 💡`--filter=blob:none` can further reduce size.
Common Pitfalls to Avoid
- ⚠️Incorrectly assuming `--depth` refers to branches or time, rather than a specific number of commits.
- ⚠️Attempting to run operations like `git bisect` or `git blame` on commits outside the shallow depth, leading to errors or incomplete results.
- ⚠️Forgetting that a shallow clone *initially* fetches only one branch (the specified one, or master/main by default) and additional branches would also be shallow if depth is maintained.
- ⚠️Not realizing that if full history is later required, `git fetch --unshallow` or a full re-clone is necessary, which can add unexpected overhead.
- ⚠️Using shallow clones for local development where developers often need to explore history, debug, or work with older versions, leading to frustration and workflow limitations.
Potential Follow-up Questions
- ❓How to unshallow later?
- ❓Impacts on submodules?
Advertisement