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?
For git 1.8.2 or above the option
--remote
was added to support updating to latest tips of remote branches: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):
or:
if you want to pull your submodules to latest commits intead of what the repo points to.
Note: If that's the first time you checkout a repo you need to use
--init
first:For older, git 1.6.1 or above you can use something similar to (modified to suit):
See git-submodule(1) for details
Here is the command-line to pull from all of your git repositories whether they're or not submodules:
If you running it in your top git repository, you can replace
"$ROOT"
into.
.Henrik is on the right track. The 'foreach' command can execute any arbitrary shell script. Two options to pull the very latest might be,
and,
That will iterate through all initialized submodules and run the given commands.
Edit:
In the comments was pointed out (by philfreo ) that the latest version is required. If there is any nested submodules that need to be in their latest version :
-----Outdated comment below-----
Isn't this the official way to do it ?
I use it every time. No problems so far.
Edit:
I just found that you can use:
Which will also recursively pull all of the submodules, i.e. dependancies.
The above answers are good, however we were using git-hooks to make this easier but it turns out that in git 2.14, you can set
git config submodule.recurse
to true to enable submodules to to updated when you pull to your git repository.This will have the side effect of pushing all submodules change you have if they are on branches however, but if you have need of that behaviour already this could do the job.
Can be done by using:
All you need to do now is a simple
git checkout
Just make sure to enable it via this global config:
git config --global submodule.recurse true