timerring

How to Partially Clone

August 21, 2025 · 0 min read
Tutorial
Git
If you have any questions, feel free to comment below. Click the block can copy the code.
And if you think it's helpful to you, just click on the ads which can support this site. Thanks!

Sometimes you encounter a large repository but only need a few directories from it. Cloning the entire repo wastes both time and disk space. Git’s sparse checkout solves this problem by letting you pull only the parts you need.

1. Initialize an empty repository #

mkdir my-partial-repo && cd my-partial-repo
git init

2. Associate the remote repository #

git remote add origin <remote repository URL>

3. Enable sparse checkout mode #

git config core.sparseCheckout true

4. Configure the directories to be checked out (the path is relative to the repository root) #

For example, only docs/ and src/utils/ directories

echo "docs/" >> .git/info/sparse-checkout
echo "src/utils/" >> .git/info/sparse-checkout

5. Pull the remote branch (e.g. main) #

git pull origin main

Related readings


<< prev | The Tips of... Continue strolling Disable SIP on... | next >>

If you want to follow my updates, or have a coffee chat with me, feel free to connect with me: