So I have a project "NewProject" that needs the same submodules than another project "OldProject".
Since I don't want to manually do the following manipulation in NewProject
git submodule add [email protected]:my-submodule.git
I hope that there is a way to re-use the .gitmodules file from OldProject
Here is what I tried for the moment:
cp OldProject/.gitmodules NewProject/.gitmodules -> ok (wouaw)git submodule init -> nothinggit submodule update -> nothinggit submodule update --init -> nothinggit submodule sync -> nothinggit submodule update --init --recursive -> nothingI've seen countless problems of people trying to change the url (or the name) of their submodule(s) but I don't think that this is similar, the new factor being that the NewProject git repository is vanilla (have no .git/modules).
So do you think there is a way to do what I intend to ?
and if yes, how can I achieve that?
not possible -> workaround via script
Your problem is the missing git submodule add call. This is what adds the submodule configuration to your .git/config file, creates a folder for your submodule in .git/modules, adds a submodule entry to .gitmodules and creates a folder in your repository in which the submodule will be checked out. I could not find a way to initialize a submodule without having added it before. Even if you copy the folder, the config entry and the .gitmodule file, any initor update call fails.
To answer your question: I do not think there is a way to skip the submodule add call and just reuse your .gitmodules file.
EDIT: And, by the way, even a newly initialized git repository has a .git/config file.
EDIT2: What exactly is the reason to avoid calling git submodule add?
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