Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git submodule: include a repo inside another

git submodule lets you include a Git repository inside another. Ideal for sharing code between projects or integrating external libraries.

Advanced

What is git submodule?

git submodule lets you integrate a Git repository into another as a versioned dependency. The parent project points to a specific commit of the submodule.

It is like having a book within a book: the parent project contains a reference to the submodule, but each has its own history and its own commits.

Git submodule syntax

git submodule add url path

Add a submodule

git submodule update --init

Initialize and download

git submodule update --remote

Update to the latest commit

Git submodule in practice

Adding, cloning, and updating submodules.

Adding a submodule

Cloning and updating

Essential submodule commands

git submodule add url

Add a new submodule

git submodule update --init

Initialize after a clone

git submodule update --remote

Update to the latest commit

git submodule status

View submodule status

git submodule foreach cmd

Run a command in each submodule

git submodule deinit path

Deinitialize a submodule

Common mistakes with git submodule

Empty folder after a clone

Submodules are not downloaded by default. Use git clone --recurse-submodules or git submodule update --init after the clone.

Forgetting to commit the update

After a git submodule update --remote, the new reference must be committed in the parent project. Otherwise, other developers will not see the update.

Difficulty removing a submodule

Removal requires several steps. Remember to deinit, rm, and clean up .gitmodules. It is one of the most confusing operations in Git.

Part of the Git Advanced guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git submodule

Master complex projects with GitQuest

Learn to manage submodules and multi-repo projects.

Start the investigations