Is it possible to know if a Git repository has submodules before we clone it, and if so what they are and what their URL is?
Also, can submodules have their own submodules, and if so, how many levels of hierarchy does Git permit?
Hosting services like Github provide a git repository browser. In the browser we can see the files and folders of a specific commit. If a repository has one or more submodules, it definitely has .gitmodules
. The names, paths, and urls of submodules are listed in .gitmodules
.
Some hosting services (not including Github) also allow git archive --remote
to download specific files.
git archive --remote=<url_to_repository> --format=zip master .gitmodules | gunzip -
If .gitmodules
exists on master
of the repository, the command prints its content. We can check if submodules are listed in it.
A submodule can have its own submodules. The levels are infinitive in theory. A commit records its own submodules only and doesn't know or care if its submodule has any submodule. There could be errors if the checked-out path is too long, which limits the levels in practice.