Pull Latest Changes for All Git Submodules

Better Stack Team
Updated on June 24, 2024

To pull the latest changes for all Git submodules in a repository, you can use the following commands:

 
git submodule update --remote --recursive

This command updates each submodule to the latest commit on its respective branch. The --remote flag tells Git to fetch changes from the remote repository, and the --recursive flag ensures that nested submodules are also updated recursively.

Note:

  • Before running this command, ensure that you've initialized and updated all submodules in your repository using git submodule init and git submodule update.
  • Be cautious when updating submodules, especially if you have uncommitted changes in them. Git may not be able to update the submodule if it has uncommitted changes.
  • After pulling changes for submodules, you may need to commit the updated submodule references in the parent repository to track the new submodule commits.
  • If you want to pull changes for a specific submodule, you can navigate to its directory and use regular Git commands (git pull, git fetch, etc.) as you would for a standalone repository.
Got an article suggestion? Let us know
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github