1

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 git@gitlab.me: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 -> nothing
  • git submodule update -> nothing
  • git submodule update --init -> nothing
  • git submodule sync -> nothing
  • git submodule update --init --recursive -> nothing

I'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?

guillaume latour
  • 187
  • 1
  • 17

1 Answers1

2

tl;dr;

not possible -> workaround via script

Details

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?

Community
  • 1
  • 1
kowsky
  • 7,265
  • 1
  • 23
  • 37