I have a repository with various nested submodules. Committing and pushing works pretty well and the changes are visible at GitHub as expected.
In the testing/production environments, new releases of this project are being deployed using these commands:
git pull --recurse-submodules
git submodule update --init --recursive
But this only updates the root project, none of the submodules are updated to the commits associated with the HEAD at GitHub. So far the only way I have found to update the whole project is to run git pull
inside each individual submodule folder.
I understand that git submodule update
is the method referenced in most places, but it is not really producing any results in this case. What could be the cause?
In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.
With Git 2.34, if the repository is cloned with the --recurse-submodules , a simple git pull will recurse into submodules. No more git config --global submodule.
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.
You need to make sure your submodules are following a branch, or they will only be checked out at a specific SHA1 (not at the latest of a branch, but the special entry of the index of your parent repo)
See "Git submodules: Specify a branch/tag" in order to make your submodule follow a branch.
Then a git submodule update --init --recursive --remote
would be enough to check out the latest from that branch.
This (git submodule update --remote
) requires git 1.8.2+ March 2013. The OP Luís de Sousa has a git 1.7.9.5 (March 2012) which doesn't offer this feature.
You have a specific version committed to your repository. For git the submodules are "files" containing a sha1-hash of the version you provided. git submodule update --init --recursive
ensures that your submodule is available in exactly that version.
For example:
git init
on a directory and have a empty repogit submodule add
which will record the current masters sha1-hash of that repo you are adding in your own repositorygit pull
in the submodule you will get the new commits and have an uncommitted change in your own repository (the new sha1-hash of the submodules master)git submodule update
will now enforce the new version is thereSo if some other contributor of your own repository updates his checkout and does a git submodule update
he will get the version you pinned. So in general the submodule update will do some work only when the submodule is not checked out or if someone changed the associated hash in your repository.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With