User_link User_link - 1 year ago 60
Git Question

Get only a submodule from a git repo

I would like to know if there's a way to only get access to a submodule directory from a git repo, without cloning the git repo fully or even using

git init
, if possible. I only need the submodules.

For example;

I only want to get the submodules from this git repo
, which contains a set of codecs.

If anyone can help me with this question, i would be grateful, thank you.

Answer Source

Basically, yes.

As CoryKramer points out in the comments on your question, you can get a list of currently active submodules from the .gitmodules file.

Since you grab that file straight from github (using, you can easily feed that into a script that will checkout the individidual modules:

curl |
awk '$1 == "url" {print $3}' |
xargs -n1 git clone

You won't be able to determine the specific commit used in each submodule without cloning the parent repository, but if all you need is the HEAD for each project you should be all set.

This solution is obviously only valid for repositories that are hosted in such a fashion that you can access individual files without cloning the entire repository. So, it works great for github hosted repositories, but it's not a general "git" solution.