0
0
Gitdevops~10 mins

Updating submodules in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Updating submodules
Start in main repo
Run git submodule update
Check submodule config
Fetch latest commit for submodule
Checkout submodule to recorded commit
Submodule updated
End
This flow shows how Git updates submodules by fetching and checking out the commit recorded in the main repository.
Execution Sample
Git
git submodule update --remote
# Updates submodules to latest commit on their tracked branch
This command updates all submodules to the latest commit on their configured remote branch.
Process Table
StepCommandActionSubmodule Commit BeforeSubmodule Commit AfterOutput
1git submodule update --remoteStart update processabc1234abc1234Fetching submodule updates...
2git fetch originFetch latest commits from submodule remoteabc1234abc1234From https://repo.url * branch 'main' -> FETCH_HEAD
3git checkout origin/mainCheckout latest commit on tracked branchabc1234def5678Note: checking out 'def5678'
4Update completeSubmodule now at latest commitabc1234def5678Submodule updated to def5678
5EndNo more updatesdef5678def5678Update finished successfully
💡 Submodule commit updated from abc1234 to def5678, matching latest remote commit.
Status Tracker
VariableStartAfter Step 2After Step 3Final
submodule_commitabc1234abc1234def5678def5678
Key Moments - 2 Insights
Why does the submodule commit change after step 3?
Because 'git checkout origin/main' moves the submodule to the latest commit on the remote branch, updating it from the old commit (abc1234) to the new one (def5678) as shown in execution_table row 3.
What happens if you run 'git submodule update' without --remote?
It will checkout the commit recorded in the main repo, not necessarily the latest remote commit. This means the submodule commit might not change, unlike in the execution_table where --remote fetches and updates.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the submodule commit after step 2?
Adef5678
Babc1234
Corigin/main
DFETCH_HEAD
💡 Hint
Check the 'Submodule Commit After' column for step 2 in the execution_table.
At which step does the submodule commit update to the latest remote commit?
AStep 1
BStep 4
CStep 3
DStep 5
💡 Hint
Look at the 'Submodule Commit After' column and see when it changes from abc1234 to def5678.
If you omit '--remote' in the update command, how would the submodule commit change?
AIt would stay at the commit recorded in the main repo
BIt would update to the latest remote commit anyway
CIt would reset to an earlier commit
DIt would delete the submodule
💡 Hint
Refer to key_moments explanation about the difference between 'git submodule update' and 'git submodule update --remote'.
Concept Snapshot
git submodule update --remote
- Fetches latest commits for submodules
- Checks out submodules to latest remote branch commit
- Updates submodule commit pointer
- Without --remote, updates to recorded commit only
- Use to keep submodules in sync with their repos
Full Transcript
This visual execution shows how the 'git submodule update --remote' command updates submodules. Starting from the main repo, the command fetches the latest commits from the submodule's remote repository. Then it checks out the submodule to the latest commit on the tracked branch, updating the submodule commit from an old commit (abc1234) to a new one (def5678). The process ends with the submodule updated successfully. Key points include understanding that without --remote, the submodule only updates to the commit recorded in the main repo, not the latest remote commit. The variable tracker shows the submodule commit changing only after the checkout step. The quiz questions reinforce these steps and differences.