Skip to content

Instantly share code, notes, and snippets.

@prachikhadke
Forked from hofnerb/sparse_clones.md
Last active December 5, 2022 04:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prachikhadke/ba5003e63a80dcd4cab823adbdb666a6 to your computer and use it in GitHub Desktop.
Save prachikhadke/ba5003e63a80dcd4cab823adbdb666a6 to your computer and use it in GitHub Desktop.
Make sparse clone
git init <repo>
cd <repo>
git remote add -f origin <url>

This creates an empty repository with your remote, and fetches all objects but doesn't check them out. Then do:

git config core.sparseCheckout true

OR since git 2.25.0

git sparse-checkout init

Now you need to define which files/folders you want to actually check out. This is done by listing them in .git/info/sparse-checkout, eg:

echo "some/dir/" >> .git/info/sparse-checkout
echo "another/sub/tree" >> .git/info/sparse-checkout

OR since git 2.25.0

git sparse-checkout set "some/dir/"
git sparse-checkout set "another/sub/tree"

Last but not least, update your empty repo with the state from the remote:

git pull origin master

Source: http://stackoverflow.com/a/13738951/2574238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment