CodeBlanks Logo Icon CodeBlanks

Summary - Submodule

Combine the submodule flow to manage an embedded repo.

Summary: Submodule workflow

A submodule lets you use an independent Git repository inside another project. Use git submodule add with a repository URL and target directory to add it. The parent repository stores a reference to a specific submodule commit.

git submodule add https://github.com/example/shared.git vendor/shared

After cloning the project, use git submodule update --init --recursive to prepare submodules and nested submodules.

Practice Complete the submodule workflow

Add https://github.com/example/chart-kit.git as a submodule at vendor/chart-kit. Then initialize and update all submodules in the parent project, including nested submodules.

Starter code

terminal
# Alt modülü ekle

# Alt modülleri başlat ve güncelle

Sample solution

terminal
git submodule add https://github.com/example/chart-kit.git vendor/chart-kit
git submodule update --init --recursive

Expected output

Submodule added at vendor/chart-kit.
Submodules initialized and updated recursively.

Questions and answers

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

1 A teammate who cloned the parent project needs to prepare nested submodules as well. Which command performs the required initialization and update operations?

  • git submodule status --recursive
  • git submodule update --init --recursive Correct answer
  • git submodule add --recursive
  • git submodule reset --recursive

Explanation: update --init --recursive initializes submodules and updates nested submodules as well.

2 Complete the submodule addition command

Question
git submodule add https://github.com/example/theme.git ____
Answer
git submodule add https://github.com/example/theme.git resources/theme

Explanation: The final argument specifies the submodule's directory path inside the parent project.

3 Submodule workflow

Term Meaning
submodule add Adds a new nested repository
URL Specifies the nested repository address
--init Initializes submodule settings
--recursive Prepares nested repositories too

All lessons in Advanced