How to clone only a folder from a git submodule?

Solution 1:

What you want to do is not feasible because you cannot clone a part of a repository.

See details in duplicate How to change a git submodule to point to a subfolder?

Solution 2:

If you:

git submodule add http://github.com/user/submodule.git

directly under my_project, you should end up with the desired organization of directories.

From git submodule add man page:

The optional argument <path> is the relative location for the cloned submodule to exist in the superproject.
If <path> is not given, the "humanish" part of the source repository is used ("repo" for "/path/to/repo.git" and "foo" for "host.xz:foo/.git").

Solution 3:

just

git submodule update --init --recursive

in the root-directory of your project and it should do what you want