Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easy way to pull latest of all git submodules

We're using git submodules to manage a couple of large projects that have dependencies on many other libraries we've developed. Each library is a separate repo brought into the dependent project as a submodule. During development, we often want to just go grab the latest version of every dependent submodule.

Does git have a built in command to do this? If not, how about a Windows batch file or similar that can do it?

like image 921
Brad Robinson Avatar asked Jun 23 '09 01:06

Brad Robinson


People also ask

What does git pull -- recurse submodules do?

git submodule foreach git pull origin master or git pull origin master --recurse-submodules is what you want if you intend to update each submodule to the latest from their origin repositories. Only then will you get pending changes in the parent repo with updated revision hashes for submodules.

Does git clone pull submodules?

It automatically pulls in the submodule data assuming you have already added the submodules to the parent project. Note that --recurse-submodules and --recursive are equivalent aliases.

Are git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.


1 Answers

If it's the first time you check-out a repo you need to use --init first:

git submodule update --init --recursive 

For git 1.8.2 or above, the option --remote was added to support updating to latest tips of remote branches:

git submodule update --recursive --remote 

This has the added benefit of respecting any "non default" branches specified in the .gitmodules or .git/config files (if you happen to have any, default is origin/master, in which case some of the other answers here would work as well).

For git 1.7.3 or above you can use (but the below gotchas around what update does still apply):

git submodule update --recursive 

or:

git pull --recurse-submodules 

if you want to pull your submodules to latest commits instead of the current commit the repo points to.

See git-submodule(1) for details

like image 113
Henrik Gustafsson Avatar answered Sep 21 '22 16:09

Henrik Gustafsson