2.1. If you want to clone a repository including its submodules you can use the --recursive parameter. If you already have cloned a repository and now want to load it's submodules you have to use submodule update .
The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.
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.
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.
After cloning the repository containing your submodules, the following command will checkout the master branch on all of these in one go:
git submodule foreach --recursive git checkout master
How about:
git submodule update --init --recursive
To initialize all submodules and submodules inside submodules. Not sure if this will checkout master though.
The question is why you checkout master. Your sub modules are pinned to a specific sha - that's also why the sub module clones are fixed to that specific commit. By not pointing to a specific sha an external repo could easily break your builds. Most definitely not what you want. Better update consciously. Builds should be reproducible and as fix as possible.
As already answered
git submodule foreach --recursive git checkout master
does the job for the branch master.
But if it is a branch that is not present in all of the submodules one can use
git submodule foreach --recursive "git checkout branchname || true"
Otherwise the command will fail on the first repo not having the specified branch.
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