DEV Community


Posted on

Quick tip: Clone a single folder from Github

Sometimes you find a repository on Github and you only really need a single folder.

How do you get it without cloning the entire repo?

Luckily Github just implemented sparse-checkout. This is a super-quick example of how it works.

Example repo

Let's say I wanted to clone Supabase's example Slack clone, which lives in the following folder:

├── connectors
├── examples
│   ├── slack-clone-basic # <--
├── libraries
├── web

Sparse Checkout

Here are all the steps I would need:

# 1. Copy an empty repo
git clone --no-checkout

# 2. Move into the empty repo
cd supabase

# 3. Initialize sparse-checkout
git sparse-checkout init --cone

#4. Checkout the folder
git sparse-checkout set examples/slack-clone-basic

And viola! Now you have just the folder you want.


sparse-checkout was introduced in Git version 2.25. If you get see an error "git: 'sparse-checkout' is not a git command" then you probably need to update. You can use git --version to see what version you're on.

If you're on Mac (and used homebrew to install git) you can run brew upgrade git.

Top comments (4)

cescquintero profile image
Francisco Quintero 🇨🇴

Juuumm, interesting. Thanks for sharing!

aleclarson profile image
Alec Larson

This helped me when upgrading git:

davidrbailey profile image
David Bailey
temesgenchali profile image

interested thank you