🔀 Git & GitHub Intermediate

What is git submodule?

Why Interviewers Ask This

This question targets practical, hands-on experience with Git & GitHub. Interviewers want to see if you've worked with these concepts in real projects, not just read about them. Strong answers include concrete examples.

Answer

Git submodules allow you to include one Git repository as a subdirectory inside another. The parent repo stores a reference (specific commit) to the submodule repo — not the content itself. When you clone the parent, submodules are empty until initialized. Adding a submodule: git submodule add https://github.com/other/lib.git vendor/lib — creates .gitmodules config file and adds the submodule directory. The parent repo records the exact commit of the submodule (pinned version). Cloning with submodules: git clone --recurse-submodules url or after cloning: git submodule update --init --recursive. Update to latest: git submodule update --remote. Working in a submodule: cd into the submodule, work normally (it's a regular Git repo), commit, then back in parent: git add submodule/path && git commit to update the tracked commit. Remove a submodule: git submodule deinit vendor/lib && git rm vendor/lib. Drawbacks: complex workflow, easy to forget updating, confusing for new contributors. Alternatives: git subtree (merges history), language package managers (npm, Maven, pip), monorepo tools. Use submodules when you need to pin to specific commits of a shared library.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong Git & GitHub candidates.