I have a git repo (abc) which has two submodules and these submodules inturn as one submodule. I need to write a shell script wherein the only the url of the repo(abc) will be given as input to clone in the workspace directory. This I was able to do using git clone <url> --recursive command. But what I also want my shell script to do is clone all the submodule repo's recursively as well inside workspace directory (not inside cloned abc repo directory as subdirectories). Can this be done using shell script? In the end the workspace directory should contain 4 subdirectories (abc, submod1, submod2, common_submod).
First clone the top-level repo to abc. Then run a loop over a list of desired submodules and clone each one recursively:
#! /bin/sh
set -e
git clone --recursive <URL> abc
for sm_path_key in `git -C abc config --file .gitmodules --name-only --get-regexp path`; do
sm_path=`git -C abc config --file .gitmodules "$sm_path_key"`
git clone --recursive abc/"$sm_path"
done
PS. Tested on my real repositories.
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