CodeBlanks Logo Icon CodeBlanks

What is a submodule?

Learn to embed another repository with a submodule.

What is a submodule?

A Git submodule allows one Git repository to be used as a separate repository inside another repository. The parent repository does not directly include the submodule's entire history; instead, it stores a reference to a specific commit in the submodule. This lets you use a shared library or independent project within another project.

project/
├── app/
└── libraries/
    └── shared-ui/

A submodule has its own Git history and working directory. It can be updated independently of the parent repository.

Parent and nested repository relationship

A parent repository containing a submodule records which commit the submodule should use. The nested repository keeps its own files and commit history separate. When you create a new commit inside the submodule, you must also record the updated submodule reference in the parent repository.

git status
# modified: libraries/shared-ui (new commits)

This structure helps you keep dependent projects on specific versions.

Practice Inspect the submodule directory

To verify that libraries/shared-ui is its own repository, enter that directory and display the Git repository root.

Starter code

terminal
# Alt modül dizinine geç

# Git depo kökünü göster

Sample solution

terminal
cd libraries/shared-ui
git rev-parse --show-toplevel

Expected output

Changed directory to libraries/shared-ui.
Repository root displayed.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 You want to use another Git repository inside a project while keeping its history separate. Which Git feature meets this need?

  • Git reflog
  • Git tag
  • Git submodule Correct answer
  • Git stash

Explanation: A submodule lets you use another Git repository inside the parent project with its own independent history.

2 Identify the submodule reference

Question
Ana depo, alt modülün belirli bir ____ bilgisini saklar.
Answer
Ana depo, alt modülün belirli bir commit bilgisini saklar.

Explanation: The parent repository records which commit the submodule should use.

3 Parts of a submodule structure

Term Meaning
Ana depo Stores the submodule reference
Alt depo Has its own commit history
Commit referansı Specifies the submodule revision
Alt modül dizini Contains the nested repository files

All lessons in Advanced