📦 CHAPTER · GIT SUBMODULE
Chef You

Repos Inside
Repos

Need to include another Git repository inside yours? git submodule embeds a repo as a sub-directory, pinned to a specific commit. A repo within a repo.

Scene I

Nested cookbooks

Chef You

Your main project is a restaurant app. It uses a shared UI library and a recipe engine that are separate repos maintained by other teams.

Instead of copy-pasting, you link them as submodules — each one tracks its own repo and stays pinned to a specific version.

📦 ADD SUBMODULES Drag a library into your project
📁 my-restaurant-app/ MAIN REPO
📄 index.html
📄 app.js
📄 package.json
📦 Click a library below to add it here as a submodule…
AVAILABLE LIBRARIES
Submodules linked!

🎉 Two repos nested inside

Each submodule is its own Git repo with its own commits. Your main repo just stores a pointer (commit hash) to the exact version you want.

Key rule: after cloning, always run git submodule update --init --recursive to actually download the submodule content.

$ git submodule add https://github.com/team/ui-lib
Cloning into 'ui-lib'...
$ git submodule update --init --recursive
Submodule path 'ui-lib': checked out 'a1b2c3d'
Epilogue
Submodules = repos inside repos.
Pinned to a specific version.
Shared code, separate histories.

Modern alternative: many teams prefer package managers (npm, pip) for dependencies. Use submodules when you need to develop the dependency alongside your project.