Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 246
Vyachaslav Gerchicov Avatar asked Apr 10 '15 09:04

Vyachaslav Gerchicov


People also ask

How do I stash everything in git?

Running the git stash command will take all the changes to tracked files in the working directory and stash them away. You can tack on the --include-untracked flag to make sure that untracked files are also included in the stash. You can take this a step further with the --all flag.

Does git stash save all changes?

This is exactly the kind of scenario git stash is designed for. Git stash saves the uncommitted changes locally, allowing you to make changes, switch branches, and perform other Git operations. You can then reapply the stashed changes when you need them.

Does git clone include submodules?

Cloning a Project with Submodules If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.

Can you have multiple stashes in git?

Multiple stash entries Subsequent stash entries are added to the beginning of the stash list. The most recent stash will have the reference stash@{0} . The stash list can contain stash entries from different branches, which could each be applied to other branches in your project.


1 Answers

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

like image 191
Shoaib Shakeel Avatar answered Sep 19 '22 21:09

Shoaib Shakeel