Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert git repo into a submodule AND move .git directory to superepo

I have a super repo and a few submodules in this repo:

MY_SUPER_REPO

  • my_sub_1
  • my_sub_2

Now I am creating a new directory that will later become a submodule:

  • my_dir_3

When I am ready for it to become a sub repo I do:

git init
git remote add origin URL

I then go to the super repo and

git submodule add URL

Now .gitmodules are updated accordingly BUT the .git directory stays in the my_dir_3 and the hooks seems to be taken from here when I work in that sub module, not from the super repo .git/modules/xyz directory. I run a script to copy hooks to .git/modules/xyz in my super repo but since the local .git folder exists in the added sub module the hooks in the super repo aren't used.

Is there any "magic" command to fix this or do I need to copy .git manually?

like image 485
Henrik Avatar asked Oct 19 '22 00:10

Henrik


1 Answers

You could slightly change your process and:

  • once you have added a remote url (git remote add origin URL), you would first push that new repo to its remote destination
  • then you delete the folder
  • finally, you add your submodule the usual way (git submodule add URL)

That way, you are sure the submodule is correctly initialized, with its .git located at the right spot.

like image 124
VonC Avatar answered Oct 27 '22 07:10

VonC