News Stay informed about the latest enterprise technology news and product updates.

How to update Git submodules

It doesn’t take a while before a developer gets used to the push and pull type of interactions required to get the latest source code from the master or the latest commit on the development branch. But git submodule updates are a little bit trickier, as the git commit you reference in the parent module isn’t always the latest code on that branch.

A git submodule update will bring the latest commits into your local Git worktree.

In this git submodule update example, we’ll show you how branches can seem out of sync between your submodule and the latest commit, and how to issue the appropriate git command to update those git submodules with the latest code.

Steps to update git submodules

To update the Git submodules in your workspace with the latest commits on the server:

  1. Clone the remote repository, if you haven’t already.
  2. Issue a git submodule update –remote command.
  3. Add any new files pulled from the repository to the Git index.
  4. Perform a git commit.
  5. Push back to origin.

Update git submodules example

If you would like to perform the update git submodules example on your local machine, use the following commands:

[email protected]:~$ git clone --recurse-submodules https://gitlab.com/cameronmcnz/surface.git
[email protected]:~$ cd sur*
[email protected]:~$ git submodule update --remote
[email protected]:~$ git add .
[email protected]:~$ git commit -m "git submodule updated"
[email protected]:~$ git push origin

The repositories used in this example are available on GitLab.

SearchAppArchitecture
SearchSoftwareQuality
SearchCloudComputing
SearchSecurity
SearchAWS
Close