0

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?

Yep
  • 653
  • 5
  • 20

2 Answers2

3

The git submodule foreach is really handy.

git submodule foreach git pull

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

Marcus Johansson
  • 2,626
  • 2
  • 24
  • 44
  • 1
    Yes, it was mainly the foreach function I was trying to explain. – Marcus Johansson Jul 16 '12 at 21:55
  • Is this the recommended way of doing this? I might make this into a little script for easy running – Yep Jul 16 '12 at 22:00
  • [This answer](http://stackoverflow.com/a/21195182/79125) describes how you can use the new `--remote` argument to `submodule update` instead of `foreach`. – idbrii Jul 31 '14 at 16:07
0

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.

Community
  • 1
  • 1
idbrii
  • 10,975
  • 5
  • 66
  • 107