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.
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
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 1git clone --filter=blob:none https://github.com/org/huge-repo.gitShallow 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 2git 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.
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 3git 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 mainSpeed up an existing clone
Background maintenance and the commit graph make day-to-day operations on a large repository far more responsive.
step 4git maintenance start git commit-graph write --reachable --changed-paths git gcCheck 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 5git 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 cloneCopy a remote repository, its full history and its branches, onto your machine.
git sparse-checkoutCheck out only part of a huge repository.
git maintenanceSchedule background upkeep so big repositories stay fast.
git commit-graphBuild an index that makes history traversal dramatically faster.
git count-objectsReport 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
My .git folder is enormous — how do I find the biggest files in history?
git count-objects -vH tells you the total size; combining git rev-list --objects with git cat-file --batch-check lists the largest blobs by name. Deleting the files now won't shrink anything — they have to be purged from history.
Read the fix →Always fixableI committed a large file and my push is rejected — how do I remove it?
If it's still the last commit, git reset --soft HEAD~1 and re-commit without it. If it's further back, purge it from history with git filter-repo --strip-blobs-bigger-than. Going forward, route large binaries through Git LFS.
Read the fix →Always fixableI cloned a repo and the submodule folders are empty — how do I fix it?
Cloning records submodules but doesn't populate them. Run git submodule update --init --recursive, or clone with --recurse-submodules next time so it happens automatically.
Read the fix →Usually recoverableGit says 'object file is empty' or 'loose object is corrupt' — can I repair it?
Corruption is almost always a few damaged object files after a crash, disk problem or a killed process. Run git fsck to identify them, delete the empty or unreadable ones, and re-fetch the good copies from your remote. If you have a remote, a fresh clone is often the fastest fix.
Read the fix →