Skip to content

Instantly share code, notes, and snippets.

@doitian
Created March 24, 2012 11:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doitian/2181511 to your computer and use it in GitHub Desktop.
Save doitian/2181511 to your computer and use it in GitHub Desktop.
git submodule-rm
#!/bin/bash
# refs http://stackoverflow.com/a/1260982/667158
function submodule_rm() {
[ -z "$1" ] && return 1
local path="$1"
local dir=$(dirname ".git/modules/$path")
git config -f .git/config --remove-section "submodule.$path" &> /dev/null
git config -f .gitmodules --remove-section "submodule.$path" &> /dev/null
git rm --cached "$1"
if [ -d ".git/modules/$path" ]; then
rm -rf ".git/modules/$path"
while rmdir "$dir" &> /dev/null; do
dir=$(dirname "$dir")
done
fi
}
submodule_rm "$@"
@doitian
Copy link
Author

doitian commented Mar 30, 2012

If the path is not added into index, just ignore the error message. The directory itself is not removed from disk, do it yourselves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment