Setup & configAlways fixable

Speed up a slow clone of a huge repository

Cloning takes forever — how do I clone a big repo faster?

Short answer

Use --filter=blob:none for a partial clone that fetches file contents lazily, and add sparse-checkout to materialise only the directories you need. --depth 1 is fastest of all but gives you no usable history.

quick fix
git clone --filter=blob:none https://github.com/org/huge-repo.git

Full history, file contents downloaded only when you actually touch them

Does this match your situation?

  • A clone runs for many minutes or times out.
  • CI spends most of its time checking out code.
  • The repository has years of history or large binary assets.
  • You only need a few directories out of a large monorepo.

Step-by-step fix

  1. Partial clone — the best general answer

    You get every commit, so log, blame and bisect all work, but file contents are fetched on demand. For most large repositories this is dramatically faster with almost no downside.

    step 1
    git clone --filter=blob:none https://github.com/org/huge-repo.git
    
  2. Shallow clone — fastest, but limited

    Only the most recent commits. Ideal for CI where you just need to build the current state, and unsuitable for anything that reads history.

    step 2
    git clone --depth 1 https://github.com/org/huge-repo.git
    
    # one branch only:
    git clone --depth 1 --single-branch --branch main <url>
    

    You can't bisect, blame far back, or diff against old tags. Convert later with git fetch --unshallow.

  3. Sparse checkout — only the folders you need

    Combine with a partial clone and a monorepo becomes workable: full history, but only the packages you actually work on ever land on disk.

    step 3
    git clone --filter=blob:none --no-checkout https://github.com/org/monorepo.git
    cd monorepo
    git sparse-checkout init --cone
    git sparse-checkout set packages/web packages/shared
    git checkout main
    
  4. Speed up an existing clone

    Background maintenance and the commit graph make day-to-day operations on a large repository far more responsive.

    step 4
    git maintenance start
    git commit-graph write --reachable --changed-paths
    git gc
    
  5. Check whether bloat is the real problem

    If the repository is huge because of committed binaries, no clone flag fixes that properly — the history itself needs cleaning.

    step 5
    git count-objects -vH
    

Why this works

A normal clone downloads every version of every file that has ever existed, which is why size grows with history rather than with the current checkout. Partial clone changes the contract: the server sends commits and trees but withholds blobs until a command actually needs one, so you keep a fully functional history at a fraction of the transfer. Sparse checkout then limits what gets written to disk. Shallow clone is cruder — it truncates history outright, which is why anything that walks backwards stops working.

If that didn’t work

  • If the repo is bloated by committed binaries, the real fix is filter-repo plus Git LFS.
  • For CI, cache the clone between runs rather than re-cloning each time.
  • Some hosts support a bundle URI that seeds the clone from a CDN - check your provider.

How to stop it happening again

  • Use Git LFS for binaries from the start so history stays lean.
  • Ignore build output and dependency directories.
  • Run git maintenance start on large repositories you work in daily.

Commands used in this guide

git clone

Copy a remote repository, its full history and its branches, onto your machine.

git sparse-checkout

Check out only part of a huge repository.

git maintenance

Schedule background upkeep so big repositories stay fast.

git commit-graph

Build an index that makes history traversal dramatically faster.

git count-objects

Report how much disk space the repository is using.

Still stuck?

Search the full command reference and every other rescue guide — there are 56 of them, covering everything from detached HEAD to force-push disasters.

Browse all guides →

Frequently asked questions

What is the fastest way to clone a large repository?

git clone --depth 1 is the fastest but gives you no usable history. For a clone you'll actually work in, --filter=blob:none is better: it downloads all commits but fetches file contents lazily, so history still works.

What's the difference between a shallow clone and a partial clone?

A shallow clone truncates history to the last n commits, so log and bisect can't see further back. A partial clone keeps every commit but omits file contents until needed, which preserves full history operations at a much smaller download.

Can I get the full history later after a shallow clone?

Yes - git fetch --unshallow downloads the rest. It takes as long as a full clone would have, so it only makes sense once you genuinely need the history.

Related rescue guides

← All Git Rescue guides