Want a copy of a huge repo without waiting for a coffee break to finish? Shallow git clone buys you speed and bandwidth by pulling only recent commits. It is perfect when you just need to build, test, or inspect the latest code without hoarding the entire history like a digital pack rat.
The key option is --depth
. A depth of 1 gives you the working tree for the latest commit and almost nothing else. That means less disk usage and faster clones. Use a larger number if you need a bit of context but still want to save time.
git clone --depth 1 --branch main REPO_URL
If you do not want every branch to follow you home add --branch
to limit the clone to one branch. That prevents unnecessary refs from being fetched and reduces surprise downloads.
Shallow is not forever. If your debugging or bisecting skills demand history you can fetch more without recloning. Fetch a fixed number of commits or remove the shallow state and pretend you were full history all along.
git fetch --depth N
to increase depth to N commitsgit fetch --unshallow
to convert the repo into a full cloneUse these when you discover some bug that lives in the past and you need context beyond the latest snapshot.
Submodules often default to full history and will quietly ruin your bandwidth savings. Initialize them shallow to keep the plan intact.
git submodule update --init --depth 1
If you skip this you may see large unexpected downloads when your build starts pulling submodule history. That is what we call developer surprise.
Shallow clones can miss tag history and annotated tags. If your release steps rely on tags fetch them explicitly or unshallow first.
git fetch --tags --depth N
or
git fetch --unshallow
--depth
and --branch
when applicable--depth
to avoid surprisesShallow clones are a pragmatic trick for version control that save time and network cycles. They are not magic. If you need to investigate ancient crimes in the commit log you will have to fetch more history. Until then enjoy a faster clone and one less reason to complain about slow CI pipelines.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.