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 int
The following worked for me on Windows.
git submodule init
git submodule update
I did this by adapting gahooa's answer above:
Integrate it with a git [alias]
...
If your parent project has something like this in .gitmodules
:
[submodule "opt/submodules/solarized"]
path = opt/submodules/solarized
url = git@github.com:altercation/solarized.git
[submodule "opt/submodules/intellij-colors-solarized"]
path = opt/submodules/intellij-colors-solarized
url = git@github.com:jkaving/intellij-colors-solarized.git
Add something like this inside your .gitconfig
[alias]
updatesubs = "!sh -c \"git submodule init && git submodule update && git submodule status\" "
Then to update your submodules, run:
git updatesubs
I have an example of it in my environment setup repo.
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:
git config submodule.recurse true
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 :
git submodule foreach --recursive git pull
-----Outdated comment below-----
Isn't this the official way to do it ?
git submodule update --init
I use it every time. No problems so far.
Edit:
I just found that you can use:
git submodule foreach --recursive git submodule update --init
Which will also recursively pull all of the submodules, i.e. dependancies.
Here is the command-line to pull from all of your git repositories whether they're or not submodules:
ROOT=$(git rev-parse --show-toplevel 2> /dev/null)
find "$ROOT" -name .git -type d -execdir git pull -v ';'
If you running it in your top git repository, you can replace "$ROOT"
into .
.
From the top level in the repo:
git submodule foreach git checkout develop
git submodule foreach git pull
This will switch all branches to develop and pull latest