Easily update all git submodules

I often use a larger Visual Studio solutions to handle a bunch of simple NuGet projects. And more often I only update references or NuGet packages.

But working with git submodules in VSCode and Visual Studio is still a pain in the apple.... Thanks got we have a foreach support inside of git submodule

So here is a simple snippet to update, commit and push all submodules inside a parent directory.

# Add all changes
git submodule foreach "git add ."
# Commit all changes, use 'true' to ignore submodules without changes
git submodule foreach "git commit -m 'Updated all NuGet references' || true"
# Push all changes
git submodule foreach "git push origin master"

For sure this wont work inside a team, because you cannot push to master. But for personal simple project I do not use any branch security / policy.

Share this article

comments powered by Disqus