Skip to content

Instantly share code, notes, and snippets.

@danielctull
Created December 25, 2010 12:12
Show Gist options
  • Save danielctull/754845 to your computer and use it in GitHub Desktop.
Save danielctull/754845 to your computer and use it in GitHub Desktop.
An extension to git to allow easy removal of submodules
#!/bin/bash
usage() {
echo "usage: git dctsubmodule remove [--hard] submodulepath"
}
if [[ ! -f .gitmodules ]]; then
echo "git submodules not in use"
exit
fi
if [[ $1 != "remove" || $2 == "--help" || $2 == "" ]]; then
usage
exit
fi
submodule=$2
hard=false
if [[ $2 == "--hard" ]]; then
submodule=$3
hard=true
fi
submodule=$( echo $submodule | sed 's/\/$//g')
git rm --cached $submodule
git config --remove-section "submodule.$submodule"
git config -f .gitmodules --remove-section "submodule.$submodule"
if [[ $hard == true ]]; then
echo "rm -rf '$submodule'"
rm -rf $submodule
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment