A lot of questions about automatically update submodules have been asked on StackOverflow including:
- Is there a way to make git pull automatically update submodules?
- Easy way to pull latest of all git submodules
- Why doesn't git checkoutautomatically dogit submodule update --recursive?
But it looks to me as for git submodules there is no single approach yet which works like svn up regarding svn-externals.
So since git is changing every day I dare to ask again:
Is there a (convenient) way to init and automatically update submodule checkouts (i.e. keep in sync with their corresponding submodule commit IDs) for checkout and pull (i.e. merge and rebase)?
Currently I have two approaches for this:
#1: create a post-checkout, post-merge and post-rewrite hook with the following content
#!/bin/sh
git submodule update --init --recursive
as you can already see this approach has several disadvantages:
- it's complicated and probably needs a script to make it working reliably
- does not work well if you use these git-hooks already
- the commit hooks are only active on this clone (has to be re-done by everyone working on this project on every single clone)
- setup is non-standard and will confuse others
#2: configure aliases for pull and checkout
git config --global alias.up 'pull --recurse-submodules'
git config --global alias.co 'checkout --recurse-submodules'
But this isn't nice neither:
- it won't --initthe submodules (can be solved by runningpull/checkoutandsubmodule updateseparately instead
- it's non-standard and won't work with scripts and snippets
- it's easy to forget to use up/coinstead ofpull/checkout
- it works only on the local machine/user
This approach would be a bit more like I want it to be if you could do something like
git config --global pull.recurseSubmodules true
git config --global pull.initSubmodules true
git config --global checkout.recurseSubmodules true
git config --global checkout.initSubmodules true
.. but you can't, do you?
 
    