gitgit-submodules

How to delete a git submodule locally?


I want to delete a submodule locally without pushing the changes to mainline.

Here is what I have done:

https://gist.github.com/myusuf3/7f645819ded92bda6677

// Remove the submodule entry from .git/config

$ git submodule deinit -f my_submodule

// Remove the submodule directory from the superproject's .git/modules directory

$ rm -rf .git/modules/my_submodule

// Remove the entry in .gitmodules and remove the submodule directory located at path/to/submodule

$ git rm -f my_submodule

Now here is what I have now:

$ git status -s -uno
D  my_submodule

Question> If I commit this change locally and later push all my local changes to main, will these commands cause the submodule(i.e. my_submodule) deleted from mainline?

Thank you


Solution

  • Yes it will be deleted on the remote branch.

    Since the changes are recorded into a commit, the submodule will also be removed on the remote branch when you push. The same thing happened when you added the submodule in the first place.

    If you only want to delete it locally, you either need not to commit the removal, or create a branch that won't be merged in the mainline.