Get started
Clone a large repository fast
A full clone of a large repository downloads every version of every file, and that can take minutes. A partial clone downloads the commits and the folders first, and only the files that you check out. Git gets the other files later, when a command needs them.
4 min read
You need git 2.26 or later.
1. Clone without the old file versions
Add --filter=blob:none to the clone:
git clone --filter=blob:none https://source.tanstack.com/@acme/app.git
With src, put the git flags after --:
src repo clone acme/app -- --filter=blob:none
Git downloads every commit and every folder, then the files of the branch that it checks out. It does not download the older versions of the files.
2. Make sure that the clone is partial
git -C app config --get remote.origin.partialclonefilter
Git prints the filter of the clone:
blob:none
3. Work as usual
git log,git status,git commitandgit pushwork as in a full clone.git switchto another branch downloads the files of that branch that you do not have yet.git diff,git log -pandgit blameof old commits download the old files that they read.
Each download is a request to the forge. So a command that reads files that you do not have needs a network connection.
Tip
Do you need no history at all, for example in a CI job? git clone --depth 1 downloads only the newest commit. See Clone only the newest commit.
Pick another filter
| Filter | What git downloads in the clone | The rest |
|---|---|---|
--filter=blob:none | Every commit and folder, and the files that it checks out | When a command needs it |
--filter=blob:limit=1m | Every commit and folder, and each file smaller than 1 MiB | When a command needs it |
--filter=tree:0 | Every commit, and the folders and files that it checks out | When a command needs it |
--filter=tree:<depth> | Every commit, and the folders and files less than <depth> levels below the top folder | When a command needs it |
The number of blob:limit can end in k, m or g, for example blob:limit=500k.
The forge refuses every other filter, and git stops with an error that says that the filter is not supported. Then clone again with one of the filters of the table.
A partial clone needs git protocol v2, the default of git 2.26 and later. A fetch over protocol v0 or v1 gets every object.
Note
src repo clone turns on git's transfer.bundleURI. So a clone of a public repository first downloads a bundle of the default branch from the CDN. Then git fetches only the newer objects.
Clone only the newest commit
A CI job that clones a large repository waits for the clone on each run. When the job needs no history, clone only the newest commit:
git clone --depth 1 https://source.tanstack.com/@acme/app.git
Git downloads that commit, with its folders and files, and no older commit. When you need more history later, add it in steps: git -C app fetch --deepen 1000.
If the forge says that it is busy
Real git on the forge's git servers answers each clone and fetch: the us server, next to the forge's web Worker, for every caller. Each server runs a limited number of clones and fetches at the same time. When your server has no free place for 5 seconds, the forge asks the server of another region. Only when no server takes the fetch, git stops before it downloads anything:
fatal: remote error: TanStack Source: this repository is busy with big fetches. Try again in a minute.
Then do one of these:
- Wait a minute, then run the same command again.
- Or fetch less. Clone with
--depth 1, then add history withgit fetch --deepen, as in the section above.
Done
You have a working clone without the old versions of the files. Git gets each missing file when a command needs it, and git push works as from a full clone.