A submodule can simply be deleted using two commands sequentially git rm <submodule path> && git commit
like below
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
Code language: Bash (bash)
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/modules/module_name
or $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
submodule="module_name
" - Delete
.gitmodules
section and submodule directory usinggit rm "$submodule"
- Delete submodule's directory in
$GIT_DIR
withrm -rf ".git/modules/$submodule"
- Commit the changes
git commit -m "Remove submodule $submodule"