Search code examples
gitgit-submodules

Stash everything in Git including all submodules?


When a project contains submodules you need to stash/unstash all of them separately. Is there a way to do it using less actions?

This link maybe helpful:

Easy way pull latest of all submodules

It is about "pull" command but there are some ways how to iterate between all the submodules.


Solution

  • You can use foreach to run a specific git command on each sub-module. For example to apply 'git stash' to every modules use this:

    git submodule foreach 'git stash'
    

    Similarly, the following command will checkout master branch and then pull any updates from the remote source for each submodule.

    git submodule foreach 'git checkout master; git pull'
    

    Read more at: http://git-scm.com/book/en/v2/Git-Tools-Submodules