Skip to content

Instantly share code, notes, and snippets.

@barrientosvctor
Created May 17, 2023 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barrientosvctor/5ac3dac3cc31654130784e2ec1fdc936 to your computer and use it in GitHub Desktop.
Save barrientosvctor/5ac3dac3cc31654130784e2ec1fdc936 to your computer and use it in GitHub Desktop.
Remove any git submodule wtih this script.
#!/bin/bash
echo "WARNING: Make sure to run the script in root directory of your project."
echo "WARNING: Before to run this script, remember to previously remove git submodules in \`/.gitmodules/\` and \`/.git/config/\` files."
echo ""
read -p "Type the git submodule path that you will remove in your project: " path
# Stage the .gitmodules file
git add .gitmodules
# Notice the change
echo "'.gitmodules' has been staged"
# Untrack the git submodule in git project
git rm --cached $path
echo "'$path' untracked"
# Remove the git submodule in .git folder
rm -rf .git/modules/$path
# Remove the git submodule folder in the project
rm -rf $path
echo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment