Skip to content

Instantly share code, notes, and snippets.

@lukebayes
Created May 13, 2021 15:15
Show Gist options
  • Save lukebayes/8466d8784acf5294154bc4ba215a80b5 to your computer and use it in GitHub Desktop.
Save lukebayes/8466d8784acf5294154bc4ba215a80b5 to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
set -eo pipefail
##########################################
# Everytime I need to remove a git submdoule, I wind up on stackoverflow trying to find the incantation.
# It seems the latest versions have made it much less painful but anyhow, here's a script that I drop into
# my ~/bin folder, chmod to 755 and use for easy, safe-ish git submodule removal.
##########################################
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
BOLD=$(tput bold)
NORM=$(tput sgr0)
sub_dir=$1
if [ -z $sub_dir ]; then
echo -e "${RED}ERROR:${NC} You must provide the relative path (e.g., vendor/bar) to the submodule you would like to remove"
exit 1
fi
if [ ! -d ${sub_dir} ]; then
echo -e "${RED}ERROR:${NC} The submodule directory provided does not exist"
exit 1
fi
echo "Attempting to remove a git submodule without all the bullshit now"
echo -e "About to remove submodule at: ${RED}${BOLD}${sub_dir}${NORM}${NC}"
echo -e "Are you sure? [${GREEN}Y/n${NC}]"
read confirmation
echo "You said, [$confirmation]"
if [ "${confirmation,,}" = "n" ]; then
echo "You declined to remove, exiting"
exit 1
fi
echo "Removing $sub_dir now"
git rm "${sub_dir}"
rm -rf ".git/modules/${sub_dir}"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment