You still need to clone the whole repository, which will have all the files. You could use the --depth
flag to only retrieve a limited amount of history.
Once the repository is cloned, the read-tree trick limits your “view” of the repository to only those files or directories that are in the .git/info/sparse-checkout
file.
I wrote a quick script to help manage the sparseness, since at the moment it is a bit unfriendly:
#!/bin/sh
echo > .git/info/sparse-checkout
for i in "$@"
do
echo "$i" >> .git/info/sparse-checkout
done
git read-tree -m -u HEAD
If you save this script as git-sparse.sh
into the path reported by calling git --exec-path
, then you can run git sparse foo/ bar/
to only “checkout” the foo and bar directories, or git sparse '*'
to get everything back again.