Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update submodules in GIT

Tags:

git

Is the following code enough to update submodules:

git submodule sync
git submodule update --init --recursive

I do a git pull of the Main Project.

Then I do

git submodule sync
git submodule update --init --recursive

to update the submodules.

Is that code enough?

like image 264
James Umeris Avatar asked Nov 14 '15 22:11

James Umeris


1 Answers

You can simply use git submodule foreach git pull to keep them updated once downloaded.

To get them along with the main project you can either use the --recursive parameter to the git clone command or use the command git submodule update --init once you have cloned the repo that contains them.

EDIT

I'd rather give a look at the documentation to fully understand the differences between the above mentioned commands, but I'll have also a try explaining them below.

The git submodule update command does the following:

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules.

That means that it doesn't update the submodules to the latest available version, instead it checkouts the actual commit with which the superproject expects to work.

On the other side, the command git submodule foreach:

Evaluates an arbitrary shell command in each checked out submodule. 

Because of that and assuming that the OP knows what the git pull command does, it's easily deducible that the combination of them can actually update all the submodules to the latest available commit.

For further details, see the link above.

like image 158
skypjack Avatar answered Sep 24 '22 13:09

skypjack