How do I clone a subdirectory only of a Git repository?
git, git-clone, repository, sparse-checkout, subdirectory
Solution
As of Git 2.19, this is finally possible, as can be seen in this answer.
Consider upvoting that answer.
Note: in Git 2.19, only client-side support is implemented, server-side support is still missing, so it only works when cloning local repositories. Also note that large Git hosters, e.g. GitHub, don't actually use the Git server, they use their own implementation, so even if support shows up in the Git server, it does not automatically mean that it works on Git hosters. (On the other hand, since they don't use the Git server, they could implement it faster in their own implementations before it shows up in Git server.)
No, that's not possible in Git.
Implementing something like this in Git would be a substantial effort and it would mean that the integrity of the client-side repository could no longer be guaranteed. If you are interested, search for discussions on "sparse clone" and "sparse fetch" on the Git mailing list.
In general, the consensus in the Git community is that if you have several directories that are always checked out independently, then these are really two different projects and should live in two different repositories. You can glue them back together using Git Submodules.
Problem
I have my Git repository which, at the root, has two subdirectories: ``` /finisht /static ``` When this was in SVN, `/finisht` was checked out in one place, while `/static` was checked out elsewhere, like so: ``` svn co svn+ssh://admin@domain.example/home/admin/repos/finisht/static static ``` Is there a way to do this with Git?
Related problems
- Using ls to list directories and their total sizes
- How to compile the Android AOSP kernel and test it with the Android Emulator?
- 'git checkout' docs claim working tree will change; why are edits not discarded?
- How to sparsely checkout only one single file from a git repository?
- How to shallow clone a specific commit with depth 1?
- Is it possible to do a sparse checkout without checking out the whole repository first?
- Managing large binary files with Git
- Download a single folder or directory from a GitHub repo