A submodule can simply be deleted using two commands sequentially
git rm <submodule path> && git commit like below
Code language: Bash (bash)
nl@ubuntu:~/youtube-dl$ git rm -f requests rm 'requests' nl@ubuntu:~/youtube-dl$ git commit -m "Deleted submodule" [master ddba8654e] Deleted submodule 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .gitmodules
The section in .
gitmodules along with the submodule working directory will be removed.
However, its history in Git directory (
$GIT_DIR, which is usually
.git) is keep around so that you can undo your changes using
git revert or checkout past commits without fetching from the original repository.
To completely delete all traces of the submodules, you can manually delete
$GIT_DIR/modules/module_name/ in case you've changed
$GIT_DIR to your own value.
A list of steps for you guys who are in need of a quick solution :
- Give the submodule a name
.gitmodulessection and submodule directory using
git rm "$submodule"
- Delete submodule's directory in
rm -rf ".git/modules/$submodule"
- Commit the changes
git commit -m "Remove submodule $submodule"