Video in progress
Cloning a big repo in CI takes 4 minutes. How do shallow and partial clones help here?
A shallow clone (--depth 1) cuts the history: only the latest commits come. A partial clone (--filter=blob:none) gets the whole history but downloads file contents only when needed. For CI the first is often enough.
📖 Answer
# only the latest state: the fastest, enough for a build
git clone --depth 1 --branch main https://git.example.com/shop.git
# the history is there, blobs are downloaded when needed
git clone --filter=blob:none https://git.example.com/shop.git
When a shallow clone gets in the way:
git describecannot find a tag when computing a version;git merge-baseor "changed files" (git diff origin/main...HEAD) needs a common ancestor, which may not be in the truncated history;- some scanning tools (Sonar's blame data) want the full history.
In that case you fetch more with git fetch --deepen=50 or --unshallow.
A partial clone is good for a developer machine: git log is fast, and the server is contacted only when you open an old file version. --filter=tree:0 is more aggressive, but then many operations get slower.
In GitHub Actions, actions/checkout uses fetch-depth: 1 by default. If you need tags or a diff, do not forget to set fetch-depth: 0.
Sign up to mark studied questions and save your progress.