#!/bin/sh set -eu help () { cat <&2 exit 120 fi cd "$1" # List the names first then act on them, because 'git submodule foreach' # gets confused if you remove the submodule while it's focusing on it. git submodule --quiet foreach --recursive 'printf %s\\n "$sm_path"' | while IFS= read -r sm_path; do git -C "$sm_path" worktree remove . git submodule deinit "$sm_path" done git worktree remove .