Last active
June 4, 2023 08:01
-
-
Save ariel-frischer/0f36896218010077b051de1164b67f97 to your computer and use it in GitHub Desktop.
Delete All Forked Github Repositories (dry-run by default)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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