after creating a git submodule by typing
git submodule add <repo> && git submodule init
my .git/config is changed, as well as a new file .gitmodules is created. It seems that I would be able to move my submodule to a specific folder within, as well as outside the repository:
$ cat gitmodules
[submodule "sub_repo"]
path = sub_repo
url = <...>
But when I try to move my repository to my parent folder and change my .gitmodules
path = ../sub_repo
it seems to ignore that module on 'git update' or 'git submodule foreach'.
What is my error in reasoning here?
Thanks a lot!
Move the submodule to its new home. Edit the config file, updating the worktree path so that it points to the new location of the submodule's working directory. Edit the . gitmodules file in the root of the master repository, updating the path to the working directory of the submodule.
The list of steps required to clone a Git repository with submodules is: Issue a git clone command on the parent repository. Issue a git submodule init command. Issue a git submodule update command.
Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .
Moving a submodule out of its parent repo into a standalone directory simply involves updating some of the metadata. With Git 2.4, the steps are as follows:
Starting from the repo, assuming the submodule is in my-submodule/
:
mv my-submodule ../
Remove the pointer .git
file in the submodule (note that it isn't a directory):
rm ../my-submodule/.git
Move the real git metadata for the submodule into the submodule's git repository:
mv .git/modules/my-submodule/ ../my-submodule/.git
Edit the .git/config
file by removing the worktree
argument, which previously pointed to a relative path inside the repo.
That's it! At this point, your parent repo will show the submodule as deleted
, while the submodule itself will work as normal (possible with a detached HEAD, which you can reset to master).
It's also possible to edit the .gitmodules
file in the parent repo, but I've found that not doing this doesn't break anything, as long as you commit the deleted submodule.
If anyone else knows a faster way to do this (such as an actual git command), I'd be all ears.
It's simply not supported, that's all. The whole point of submodules is to basically have one repository in another one.
If you don't want to do this, don't use submodules. Simply clone that other repository.
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