Last Updated: July 19, 2020
·
8.483K
· radamanthus

Quickly clone a large git repo

We usually do this:

git clone <url>

Works most of the time, except when you have a 1GB repo with lots of old branches.

You should instead do this:

git clone -b <branch> <url> --depth=1

This retrieves just the latest commit for the specific branch you specify.

You can also use the depth directive when pulling a branch:

git pull --rebase origin <branch> --depth=1

2 Responses
Add your response

Bear in mind that you can't commit to a shallowly cloned repo.

over 1 year ago ·

Actually, you can, if the history is simple enough. See: http://stackoverflow.com/questions/6900103/why-cant-i-push-from-a-shallow-clone

It works most of the time if you have branches that don't diverge much from each other.

over 1 year ago ·