Advanced

How to use Git submodules

Include and manage external repositories inside your repository.

Add a submodule
git submodule add https://github.com/user/repo.git path/to/submodule

Adds an external repository as a submodule at the specified path.

Clone repo with submodules
git clone --recurse-submodules https://github.com/user/repo.git

Clones the repo and automatically initializes and updates all submodules.

When to use: Cloning a project that uses submodules.

Initialize submodules after cloning
git submodule update --init --recursive

Initializes and updates all submodules after a plain clone.

When to use: If you cloned without --recurse-submodules.

Update all submodules
git submodule update --remote

Fetches and updates all submodules to their latest remote commits.

← Back to Git Reference