Reputation: 8312
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 master
or
git submodule foreach --recursive git pull origin master
but cannot pull files of Twig.
Upvotes: 440
Views: 648754
Reputation: 427
How about
git config --global submodule.recurse true
and forget it?
See the git book documentation.
Upvotes: 15
Reputation: 1
I had one submodule causing issues (the 'fatal:...' that Sanandrea reported, above). Navigated to the submodule and used 'git clean -dfx' resolved it.
Upvotes: 0
Reputation: 50963
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.
Upvotes: 5
Reputation: 94683
git submodule update --recursive
You will also probably want to use the --init option which will make it initialize any uninitialized submodules:
git submodule update --init --recursive
Note: 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.
Upvotes: 947
Reputation: 18925
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 --merge
You 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'
Upvotes: 27
Reputation: 3916
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'
Upvotes: 27
Reputation: 39243
The way I use is:
git submodule update --init --recursive
git submodule foreach --recursive git fetch
git submodule foreach git merge origin master
Upvotes: 61