-
Notifications
You must be signed in to change notification settings - Fork 30
Description
Alright, buckle up—time for a ride through the land of git sparse-checkout, a.k.a. “clone only what you actually care about and ignore the rest of the repo bloat.” 🚀
🧠 What is git sparse-checkout?
In simple terms:
It lets you tell Git: “Yo, I only want this one folder or file from the repo. Don’t bother pulling the rest.”
No more downloading 10GB of junk just to get your cute little nvim config.
🎯 Why Use It?
-
You only care about a subdirectory (e.g.,
nvim/.config/nvim) -
You're scripting or automating setups (like dotfiles) and want speed
-
You're low on space or attention span (me too, tbh)
💥 How It Works (Real Example)
You want only nvim/.config/nvim from a repo.
🧱 Step-by-step:
git clone --filter=blob:none --no-checkout https://github.com/username/dotfiles.git
cd dotfiles
git sparse-checkout init --cone
git sparse-checkout set nvim/.config/nvim
git checkout
🧩 Explanation:
| Command | What it does |
|---|---|
| --filter=blob:none | Tells Git: don’t fetch all file content upfront (lazy loading = fast clone) |
| --no-checkout | Clone the repo without actually putting files on disk |
| sparse-checkout init --cone | Enables sparse mode using a “cone” pattern (easier for directories) |
| sparse-checkout set path/ | Defines the only subdir(s) you want to check out |
| git checkout | Pulls just those files to your working directory |
🧪 Want to Grab Multiple Folders?
git sparse-checkout set nvim/.config/nvim zsh kitty/.config/kitty
Easy.
🔄 Switching Folders Later?
git sparse-checkout set other/folder
git checkout
Boom. Just swaps it.
🧽 To Go Back to Normal Full Checkout
git sparse-checkout disable
git checkout
Now Git tracks the whole repo like usual again.
⚠️ Heads Up
-
You still clone the entire repo metadata, just not the full contents
-
Not meant for "security by obscurity"—it's about convenience, not access control
TL;DR
git sparse-checkout = ✂️ "Just give me the folder I care about."
Perfect for dotfiles, monorepos, or if you have commitment issues with full clones.
Wanna cook a custom script that auto-sparse-checks your nvim setup? Say the word.