Skip to content

Instantly share code, notes, and snippets.

@kljensen
Created August 15, 2022 17:48
Show Gist options
  • Save kljensen/83f2bd084184a1fffb57f8fa181ce214 to your computer and use it in GitHub Desktop.
Save kljensen/83f2bd084184a1fffb57f8fa181ce214 to your computer and use it in GitHub Desktop.
Bulk Delete GitHub Repos
#!/bin/sh
# This shell script will search for all repos matching a
# provided organization and regex. It will list those for
# you and, if you confirm, DELETE YOUR REPOS. 🔥🔥🔥⚠️⚠️⚠️
# It requires 'gh', the GitHub command line interface.
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Illegal number of parameters $*"
echo "Usage: $0 USER/ORG REGEX"
exit;
fi
REPOS=$(gh repo list "$1" -L 1000 --json owner,name --template '{{range .}}{{.owner.login}}/{{.name}}{{printf "\n"}}{{end}}' |grep "$2")
printf "The following repos will be deleted:\n\n%s\n" "$REPOS"
delete_repos () {
while IFS= read -r line; do
gh repo delete "$line" --confirm
done <<< "$REPOS"
}
read -p "Continue (yes/no)?" choice
case "$choice" in
[yY][eE][sS]) delete_repos ;;
n|N ) echo "no";;
* ) echo "invalid";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment