How do I remove a Git submodule?
By the way, is there a reason I can't simply do git submodule rm whatever
?
In modern git (I'm writing this in 2022, with an updated git
installation), this has become quite a bit simpler:
git rm <path-to-submodule>
, and commit.This removes the filetree at <path-to-submodule>
, and the submodule's entry in the .gitmodules
file. I.e. all traces of the submodule in your repository proper are removed.
As the docs note however, the .git
dir of the submodule is kept around (in the modules/
directory of the main project's .git
dir), "to make it possible to checkout past commits without requiring fetching from another repository".
If you nonetheless want to remove this info, manually delete the submodule's directory in .git/modules/
, and remove the submodule's entry in the file .git/config
. These steps can be automated using the commands
rm -rf .git/modules/<path-to-submodule>
, andgit config --remove-section submodule.<path-to-submodule>
.Older community wiki instructions:
Via the page Git Submodule Tutorial:
To remove a submodule you need to:
.gitmodules
file..gitmodules
changes:git add .gitmodules
.git/config
.git rm --cached path_to_submodule
(no trailing slash)..git
directory:rm -rf .git/modules/path_to_submodule
git commit -m "Removed submodule <name>"
rm -rf path_to_submodule
See also: alternative steps below.
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