Module 7 Lesson 4: Updating and synchronizing submodules
·DevOps

Module 7 Lesson 4: Updating and synchronizing submodules

Stay up to date. Learn how to pull the latest changes from a submodule's remote and how to synchronize your parent project when a teammate updates a submodule's version.

Module 7 Lesson 4: Updating and synchronizing submodules

Submodules are "frozen" at a specific commit. If the author of the UI library you are using releases a new feature, your parent project won't see it automatically. You have to explicitly move the pointer.

In this lesson, we learn how to update submodules and how to stay in sync with your team.


1. Updating a Submodule to the latest version

If you want your submodule to use the latest code from its main branch:

# Enter the submodule
cd libs/ui

# Fetch and merge changes
git fetch
git merge origin/main

# Go back to the parent project
cd ../..

# See that the parent project tracks a new ID
git status

Shortcut: You can do this without leaving the parent directory:

git submodule update --remote libs/ui

2. Pushing the Update to the Team

Remember: the parent repository only tracks the Commit ID. If you update the library to a new version, you must commit that "New ID" to the parent repo so your colleagues get it too.

git add libs/ui
git commit -m "Update UI library to latest version"
git push

3. Synchronizing when a Colleague updates

If a teammate updates a submodule and you git pull the parent project, your local folder won't update its submodule content automatically. You will see a git status that says the submodule has "modified content."

To fix this and download the specific version your teammate chose:

git submodule update
graph TD
    Colleague["Teammate (Push new ID)"] --> Server["GitHub (Parent Repo updated)"]
    Server -- "git pull" --> You["Your Local (Parent tracks new ID)"]
    You -- "Submodule folder still has old code" --> Fix["git submodule update"]
    Fix --> Done["Local Submodule folder matches Teammate's choice"]

Lesson Exercise

Goal: The Sync Cycle.

  1. In your git-practice repo, go into your submodule folder.
  2. Manually commit a small change inside the submodule (if you have permission) or just git checkout an older commit ID in the submodule.
  3. Go back to the parent repo. Run git status. Notice it says: modified: external/mylib (new commits).
  4. Commit this "Pointer change" in the parent repo.
  5. Now, run git submodule update to see it confirm you are in sync.

Observation: You'll see that managing submodules is a "Double Commit" process. You commit in the library, and then you commit in the parent.


Summary

In this lesson, we established:

  • Submodules stay at a fixed commit until manually updated.
  • git submodule update --remote grabs the latest from the submodule's server.
  • You must commit the "New ID" in the parent repo after updating.
  • git submodule update (without --remote) syncs your local folder to match the parent project's current tracking ID.

Next Lesson: Sometimes dependencies aren't needed anymore. We’ll learn Lesson 5: Removing submodules.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn