Updating a submodule

suggest change

A submodule references a specific commit in another repository. To check out the exact state that is referenced for all submodules, run

git submodule update --recursive

Sometimes instead of using the state that is referenced you want to update to your local checkout to the latest state of that submodule on a remote. To check out all submodules to the latest state on the remote with a single command, you can use

git submodule foreach git pull <remote> <branch>

or use the default git pull arguments

git submodule foreach git pull

Note that this will just update your local working copy. Running git status will list the submodule directory as dirty if it changed because of this command. To update your repository to reference the new state instead, you have to commit the changes:

git add <submodule_directory>
git commit

There might be some changes you have that can have merge conflict if you use git pull so you can use git pull --rebase to rewind your changes to top, most of the time it decreases the chances of conflict. Also it pulls all the branches to local.

git submodule foreach git pull --rebase

To checkout the latest state of a specific submodule, you can use :

git submodule update --remote <submodule_directory>

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents