Skip to main content

git submodule command examples

Examples of git submodule commands.

Fetch git submodules code

Presence of the .gitmodules file in the project root indicates that it has git submodules. An example of such file:

[submodule "submodule_name"]
path = path from the project root
url = submodule repository url
branch = submodule repository branch

After cloning the parent repository, the git submodules directories are empty. In order to fetch their code:

git submodule init
git submodule update

The first command registers submodules for their corresponding paths. The second one checks out the code.

Alternatively, the above two commands can be combined into one:

git submodule update --init

In order to checkout submodules inside submodules, a --recursive flag can be added to command:

git submodule update --init --recursive

Check code changes for submodules

git diff --submodule=diff

More about git submodules: Git Submodules