Skip to content

Instantly share code, notes, and snippets.

@sodonnell
Last active March 2, 2020 09:31
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/8337bec88616af6a070a4df1a8ce927d to your computer and use it in GitHub Desktop.
Save sodonnell/8337bec88616af6a070a4df1a8ce927d to your computer and use it in GitHub Desktop.
Safely cleaning-up crusty ol' github forks from your repository list using python...
#!/usr/bin/env python3
#
# 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
#
from github import Github
gh=Github('Add your github Token here')
forks=0
for repo in gh.get_user().get_repos():
if (gh.get_repo(repo.full_name).fork):
forks=forks+1
confirm = input("Remove forked repo: "+ repo.full_name +"? [Y/N]")
if (confirm == "Y"):
gh.get_repo(repo.full_name).delete()
print("Deleted: "+ repo.full_name)
else:
print("Ignored: "+ repo.full_name)
if forks == 0:
print("No forked repos found.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment