Skip to content

Instantly share code, notes, and snippets.

@JeViCo
Created June 20, 2025 14:38
Show Gist options
  • Select an option

  • Save JeViCo/277401bd22d6f9db98eca5723eef1ecf to your computer and use it in GitHub Desktop.

Select an option

Save JeViCo/277401bd22d6f9db98eca5723eef1ecf to your computer and use it in GitHub Desktop.
#!/bin/bash
# Exit on errors
set -e
# List all submodule paths
submodules=$(git submodule status | awk '{print $2}')
# Remove each submodule
for submodule in $submodules; do
echo "Removing '$submodule'"
git submodule deinit -f -- "$submodule"
rm -rf ".git/modules/$submodule"
git rm -f "$submodule"
done
# Remove .gitmodules if it exists
[ -f .gitmodules ] && git rm -f .gitmodules
# Commit changes
git commit -m "Remove all submodules"
echo "All submodules removed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment