I have cloned a project and customized it. the project is using some extra projects as submodules. I have setup mine git repository and push the main project there. but I d
I don't think there is such a way with git. However, you could just do a shell script that iterates your list and calls git submodule add
on each of them, one by one.
Why just copying them to .gitmodules or to .git/index won't do the trick:
The "git submodule add" command does a couple of things:
- It clones the submodule under the current directory and by default checks out the master branch.
- It adds the submodule's clone path to the ".gitmodules" file and adds this file to the index, ready to be committed.
- It adds the submodule's current commit ID to the index, ready to be committed.
(source)
So you would be missing the last step, and git submodule init/update expect the commit id to be already in place. That is why you need git submodule add
.
Based on @eis suggestion, you have to create a script to make all the git add
commands.
A way to do that is to create the .gitmodules
containing your needs, then parse it with a script like this one:
iterator=1;
subpaths=$(git config --file .gitmodules --get-regexp path | awk '{ print $2}');
subrepos=$(git config --file .gitmodules --get-regexp url | awk '{ print $2}');
for path in $subpaths; do
repo=$(echo "$subrepos"| sed $iterator'q;d');
git submodule add $repo $path;
let iterator++;
done