Two different methods to automate the process of removing a submodule from a git repo with a single command. Adapted from here.
NOTE: A commit is made during removal, so it is best to commit any other changes prior to executing the command.
- Create a new file anywhere in your shell's search paths (i.e.
~/.local/bin) - Copy the following
#!/usr/bin/bash
git rm "$1"
rm -rf ".git/modules/$1"
git config -f ".git/config" --remove-section "submodule.$1" 2> /dev/null
git commit -m "Remove submodule $1"- Make it executable
chmod u+x ~/.local/bin/gitsubrm - Run it in terminal from the project root:
gitsubrm relative/path/submodule
- Somewhere in a file that gets sources by your shell (i.e.
~/.bashrc) - Copy the following
gitsubrm() {
git rm "$1"
rm -rf ".git/modules/$1"
git config -f ".git/config" --remove-section "submodule.$1" 2> /dev/null
git commit -m "Remove submodule $1"
}- Run it in terminal from the project root:
gitsubrm relative/path/submodule(after shell restart/re-source)