Skip to content

Instantly share code, notes, and snippets.

@manashmandal
Last active March 4, 2019 05:46
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 manashmandal/04774f2b689845494e63393897f62dd5 to your computer and use it in GitHub Desktop.
Save manashmandal/04774f2b689845494e63393897f62dd5 to your computer and use it in GitHub Desktop.
Batch Delete GitHub Forked Repository
# Install tqdm and requests to run this script
import requests
from tqdm import tqdm
ACCESS_TOKEN = "ACCESS_TOKEN_WITH_DELETE_ACCESS"
USERNAME = "your-github-username"
LIST_REPOSITORY = "https://api.github.com/users/your-github-username/repos?page={}"
API_DELETE_REPO = "https://api.github.com/repos/your-github-username/{}"
repo_list = []
for i in tqdm(range(1, 201)):
repositories = requests.get(LIST_REPOSITORY.format(i), auth=(USERNAME, ACCESS_TOKEN)).json()
filtered = [repo for repo in repositories if repo['fork'] == True]
repo_list.extend("".join(r['url'].split('/')[-1]) for r in filtered)
for repo in tqdm(repo_list):
requests.delete(API_DELETE_REPO.format(repo), auth=(USERNAME, ACCESS_TOKEN))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment