Skip to content

Instantly share code, notes, and snippets.

@sodonnell
Last active March 2, 2020 08:51
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 sodonnell/d9d38582fd1df5698c31c1068910ee90 to your computer and use it in GitHub Desktop.
Save sodonnell/d9d38582fd1df5698c31c1068910ee90 to your computer and use it in GitHub Desktop.
Safely cleaning-up crusty github forks from your repository list using bash...
#!/usr/bin/env bash
#
# This script is intended to interactively help you remove stale/unwanted github forks
# from your repo list, without accidently removing any of your actual (non-forked) repos.
#
# The use case for this is simple: I forked wayyyy too many repos that I should
# have otherwise 'starred', and wanted to clean-up my repository list.
#
# Manually purging all of my forked github repos via the github.com webui would take
# far too much effort, so I decided to automate the majority of the process.
#
# I didn't want to remove all of my forked repos, and I didn't want to remove
# ANY of my personal repos, so I made this interactive script to help me
# SAFELY dictate which forked repos that I did want purged.
#
# Author: Sean O'Donnell - https://github.com/sodonnell
#
API_TOKEN="Add your github Token here"
API_URL=https://api.github.com
function scrape_forks()
{
curl -s GET "${API_URL}/user/repos" -H "Authorization: Bearer ${API_TOKEN}" | jq -r '.[] | select(.fork) | .full_name'
}
function delete_repo()
{
curl -X DELETE "${API_URL}/repos/${fork}" -H "Authorization: Bearer ${API_TOKEN}"
}
forks=`scrape_forks`
if [ -z $forks ]; then
echo "No forked repos found."
else
for fork in ${forks}; do
echo -e "[Warning] Permanently remove repo: ${fork} (Y/N)?"
read CONFIRM
if [ $CONFIRM == "Y" ]; then
delete_repo
echo -e "Deleted: ${fork}\n"
else
echo -e "Ignored: ${fork}\n"
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment