CodeBlanks Logo Icon CodeBlanks

submodule update

Learn submodule sync with git submodule update.

git submodule update

When you clone a parent repository, submodule directories may initially be empty. Use git submodule update to fetch the recorded submodule commits and prepare their working directories. Add the --init option when the submodule configuration needs to be initialized first.

git submodule update --init

This operation uses the submodule commit references recorded by the parent repository.

Recursive updates

A submodule can itself contain other submodules. In such nested structures, updating only the top level may not be enough. The --recursive option includes submodules inside other submodules in the operation.

git submodule update --init --recursive

This command initializes the required submodule configurations and checks out recorded commits for nested submodules as well.

Practice Initialize and update submodules

Initialize all submodules in the project and check out their recorded commits, including nested submodules.

Starter code

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

Expected output

Submodules initialized and updated recursively.

Questions and answers

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

1 You have just cloned a repository, and its submodule configuration has not yet been initialized. Which command is appropriate?

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

Explanation: --init initializes the submodule configuration, while update checks out the recorded commits.

2 Update nested submodules

Question
git submodule update --init ____
Answer
git submodule update --init --recursive

Explanation: The --recursive option also updates submodules nested inside other submodules.

3 Submodule update options

Term Meaning
--init Initializes submodule configuration
--recursive Processes nested submodules
git submodule update Checks out the recorded commit
Ana depo referansı Defines the target submodule commit

All lessons in Advanced