How to shallow clone and sparse checkout in Git

· Category: Git

Short answer

Shallow clones download only recent history; sparse checkouts allow you to work with only specific directories.

Steps

  1. Shallow clone (last 10 commits):
git clone --depth 10 https://github.com/user/repo.git
  1. Sparse checkout (specific folder):
git clone --filter=blob:none --no-checkout https://github.com/user/repo.git
cd repo
git sparse-checkout set src/components
  1. Fetch more history later:
git fetch --unshallow

Tips

  • Shallow clones are great for CI pipelines that only need the latest code.
  • Sparse checkout is useful for monorepos where you only work in one project.
  • Partial clones (--filter) reduce data transfer without depth limits.

Common issues

  • Shallow clones cannot push or perform some operations until deepened.
  • Sparse checkout requires Git 2.25+ for the simplified command set.