Skip to content

Instantly share code, notes, and snippets.

@ariel-frischer
Last active June 4, 2023 08:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariel-frischer/0f36896218010077b051de1164b67f97 to your computer and use it in GitHub Desktop.
Save ariel-frischer/0f36896218010077b051de1164b67f97 to your computer and use it in GitHub Desktop.
Delete All Forked Github Repositories (dry-run by default)
#!/bin/bash
USERNAME="GITHUB-USERNAME"
# Download github cli -> https://cli.github.com/
# You may need to run:
# chmod +x delete_forked_repos.sh
# gh auth login
# gh auth refresh -h github.com -s delete_repo
# Parse command-line options
dry_run=true
while [[ "$#" -gt 0 ]]; do
case $1 in
--delete)
dry_run=false
;;
*)
echo "Unknown option: $1" >&2
exit 1
;;
esac
shift
done
result=$(gh repo list --fork | awk '{print $1}' | grep -e "^$USERNAME")
if [[ -z $result ]]; then
echo "No forked repositories found for @$USERNAME"
else
echo "DRY RUN: Would delete the following repositories: "
echo "$result" | while read full_name; do
if [ $dry_run == true ]; then
echo "$full_name"
else
echo "Deleting $full_name"
gh repo delete $full_name --yes
fi
done
fi
if [ $dry_run == true ]; then
echo "To actually delete use the --delete option."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment