I wrote the below script to push all the changes in the workspace, both in the submodules and the superproject. However, it sounds a little odd that, it is this complex to do wh
The command git push --recurse-submodules=on-demand
does not work if you have submodules which contain submodules. (git
version: 2.20.1)
Add the following alias in your ~/.gitconfig
file:
[alias]
push-all = "! find . -depth -name .git -exec dirname {} \\; 2> /dev/null | sort -n -r | xargs -I{} bash -c \"cd {}; git status | grep ahead > /dev/null && { echo '* Pushing: {}'; git push; }\""
Then issue git push-all
in your parent git folder.
!
: We are issuing a non-git command.find . -depth -name .git -exec dirname {} \\; 2> /dev/null
: Find all submodules (and git repositories, which wouldn't harm)| sort -n -r
: Sort by path depth, deepest will be first.| xargs -I{} bash -c \"
: Pass directories to the following commands:
cd {};
: cd
to the target directory.git status | grep ahead > /dev/null
: Test if it is necessary to push this repository.&& { echo '* Pushing: {}'; git push; }\""
: Inform and push.