--- /dev/null
+#! /bin/sh
+# See https://stackoverflow.com/q/1260748/7976758
+
+if [ $# != 1 ]; then
+ echo "Usage: $0 submodule_name" >&2
+ exit 1
+fi
+
+cd `git rev-parse --show-toplevel` || exit 1
+if [ \! -f .gitmodules ]; then
+ echo "The command must be run in the top-level directory" >&2
+ exit 1
+fi
+
+name="$1"
+path="$(git config -f .gitmodules --get "submodule.$name.path")"
+
+if [ -z "$path" ]; then
+ echo "Error: submodule $name does not exist" >&2
+ exit 1
+fi
+
+git submodule deinit -f -- "$path"
+rm -rf .git/modules/"$name"
+exec git rm -rf "$path"