My project struture
ProjectA
-FrameworkA (submodule)
--Twig (submodule of FrameworkA)How I can update submodules recursively? I already tried some git commands (on ProjectA root)
git submodule foreach git pull origin masteror
git submodule foreach --recursive git pull origin masterbut cannot pull files of Twig.
16 Answers
git submodule update --recursiveYou will also probably want to use the --init option which will make it initialize any uninitialized submodules:
git submodule update --init --recursiveNote: in some older versions of Git, if you use the --init option, already-initialized submodules may not be updated. In that case, you should also run the command without --init option.
The way I use is:
git submodule update --init --recursive
git submodule foreach --recursive git fetch
git submodule foreach git merge origin master 3 As it may happens that the default branch of your submodules are not master (which happens a lot in my case), this is how I automate the full Git submodules upgrades:
git submodule init
git submodule update
git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx' 4 In recent Git (I'm using v2.15.1), the following will merge upstream submodule changes into the submodules recursively:
git submodule update --recursive --remote --mergeYou may add --init to initialize any uninitialized submodules and use --rebase if you want to rebase instead of merge.
You need to commit the changes afterwards:
git add . && git commit -m 'Update submodules to latest revisions' 1 You can add the following to your Makefile:
submodule: git submodule update --init --recursive git submodule foreach 'git fetch origin; git checkout $$(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'Then you can simple run make submodule everytime you want to update submodules.
I had one submodule causing issues (the 'fatal:...' that Sanandrea reported, above). Navigated to the submodule and used 'git clean -dfx' resolved it.
1