Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is a Git submodule?

SHORT ANSWER

A submodule lets one repository contain another repository at a fixed commit. The parent stores only the URL and the exact commit hash, so the child's history stays separate.

Explain it simply

Think of a project report that includes a reference book. You do not photocopy the book into your report; you write its title and edition. Anyone reading can fetch the same edition.

The parent repo records a pointer: URL plus a specific commit of the child, listed in .gitmodules. Update the child to a new commit and the parent shows a changed pointer, which you commit. Use it for shared code across projects, such as a common UI library, when you need exact version control of that code.

Example

bash
git submodule add https://github.com/team/ui-kit.git libs/ui-kit
git commit -m "Add ui-kit submodule"
cat .gitmodules
# [submodule "libs/ui-kit"] path = libs/ui-kit url = https://github.com/team/ui-kit.git

What to say in the interview

"A submodule embeds another repository inside mine at a specific commit. The parent stores only the URL and commit hash in .gitmodules and the index, so the child's history remains separate and version is pinned precisely."

#git#submodules#dependencies

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.