Git & GitHub Interview Question #113

What is a Git submodule?

Advanced GitHub Actions, Repository Internals, Submodules, LFS & Diagnostic Tools Senior Advanced

Quick Interview Answer

A Git submodule lets one repository record a reference to a specific commit of another repository. The parent repository tracks the submodule path and the referenced commit rather than embedding the other repository's full history as ordinary files.

Detailed Explanation

A Git submodule lets one repository record a reference to a specific commit of another repository. The parent repository tracks the submodule path and the referenced commit rather than embedding the other repository's full history as ordinary files.

Submodules are useful when projects must preserve separate repository histories, but they add workflow complexity because cloning or updating the parent does not automatically behave like a single normal repository.

Code Example

git submodule add https://github.com/example/shared-library.git libs/shared-library

git commit -m "Add shared library submodule"