Yep
Yep

Reputation: 653

How to make script to update git submodules?

I have a project that has submodules added. Thing is, I always want these submodules up to date with the current version. How can I always tell these submodules to look for the latest commit and sync themselves with that?

Upvotes: 0

Views: 1611

Answers (2)

idbrii
idbrii

Reputation: 11916

submodules to look for the latest commit and sync themselves with that

Marcus Johansson's answer explains how to make the submodules get to the latest for their respective origins (if your main project is game, but it contains a graphics and logic libraries as submodules, then the graphics and logic libraries will be at latest).

If you want your submodules to be updated to the lastest used by your main project ("game" in my example), then you can use

git pull --recurse-submodules

when you update your main project to also update the submodules. Also, you can always use

git submodule update --init

to update your submodules to the main project's versions.

This is useful when your main project needs to be kept in sync with versions of the libraries (if updating a library changes their API, you only want to update it if someone updated the main project to match).

See also this answer.

Upvotes: 0

Marcus Johansson
Marcus Johansson

Reputation: 2667

The git submodule foreach is really handy.

git submodule foreach git pull

This will do a pull(i.e. fetch/merge) in all submodules.

Upvotes: 3

Related Questions