submodule update
- Git course
- Advanced
- Lesson 15/56
- 4 min
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 --initThis 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 --recursiveThis 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
# Alt modülleri başlat ve güncelleExpected 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
git submodule update --init ____
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 |