SVN externals is a really nice feature I used a lot. Switching to git I was really missing it. Of course there is git-submodule but it’s not the same. Now, with version 1.7 git supports so called sparse checkouts which allow you to only include specific sub directories of a repository in your project. You still need to clone the whole repository, but afterwards you can tell git to only show the specified sub directories.
Here is how it works:
- clone the other repository (in my case, for a Rails app, I did it in vendor/plugins/)
git clone <repository_url> <directory>
- cd to <directory>
cd <directory>
- enable sparsecheckout
git config core.sparsecheckout true
- add directories you want to have in your checkout to
.git/info/sparse-checkout, e.g.echo app/models/ > .git/info/sparse-checkout echo lib/ >> .git/info/sparse-checkout
- run read-tree
git read-tree -m -u HEAD
ls now shows
app lib
Forgot a directory you wanted to include? Just repeat step 4 and 5.
Awesome! Exactly what I was looking for…
What if I want to checkout all but one? Is there an exclusion command?
And, what about files? Do they have to be added to .git/info/sparse-checkout as well?
Thanks
Just found that you can use negate as in .gitignore – exclamation mark (!).
http://schacon.github.com/git/git-read-tree.html#_sparse_checkout
These command should be run on server side on client also let me how can take single file git pull and git push command.