Skip to content

Instantly share code, notes, and snippets.

@pradyumnac
Last active January 9, 2023 16:35
Show Gist options
  • Save pradyumnac/f572e5e0aa069fb1215bda8cce6ebf3d to your computer and use it in GitHub Desktop.
Save pradyumnac/f572e5e0aa069fb1215bda8cce6ebf3d to your computer and use it in GitHub Desktop.
Github CLI - Delete github repos from terminal
#!/usr/bin/env bash
# BE EXTRA CAREFUL with repo deletion. There is no way to recover repository once its deleted.
# Do this AT YOUR OWN RISK
# Pre-requisites: gh cli, awk
# Selection through file edit
# gh repo list -L 100 | awk '{print $1}' | sed 's,.*/,,') > repo.remote.list.all
# gh repo list -L 100 --source | awk '{print $1}' | sed 's,.*/,,') > repo.remote.list.all # non forked
# Edit this and save as repo.remote.all.delete
# declare -a repoarray=( $(cat repo.remote.delete) )
# or
# Interactve selection: you need to have gum installed as well
repoall=$(gh repo list -L 100 | awk '{print $1}' | sed 's,.*/,,')
declare -a repoarray=( $(echo -e "$repoall"|gum filter --no-limit) )
if [[ ${#repoarray[@]} -eq 0 ]]; then echo "Cancelled by user.."; exit 1; fi
echo "Deleting ${repoarray[@]}.."
echo "################ WARNING ################################################"
echo "This process is completely irreversible.. You will permanently loose data"
echo "#########################################################################"
echo
read -p "Are you sure? (y/N)" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then exit 1; fi
for i in "${repoarray[@]}"
do
echo "Deleting $i ..";
gh repo delete $i
# gh repo delete $i --confirm;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment