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

How to update Git submodules

It only takes a short while before a developer is used to the push and pull type of interactions required to get the latest source code from 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 show you how branches can seem to be 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

The list of steps required to update the Git submodules in your workspace with the latest commits on the server are:

  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:

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

The repositories used in this example are available on GitLab.

 

 

 

 

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchAppArchitecture

SearchSoftwareQuality

SearchCloudComputing

SearchSecurity

SearchAWS

Close