Skip to content

Instantly share code, notes, and snippets.

@janeczku
Last active April 21, 2020 03:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save janeczku/c9111b2a001caffe2952 to your computer and use it in GitHub Desktop.
Save janeczku/c9111b2a001caffe2952 to your computer and use it in GitHub Desktop.
Batch delete those unused stale forked repositories in your Github account

Cleaning up your Github account from those repositories you once forked and then forgot about is a tedious process when done manually.

Lets speed up this process with some automagic:

  1. Open all repositories that you want to delete in new browser tabs
  2. Use https://chrome.google.com/webstore/detail/onetab/chphlpgkkbolifaimnlloiipkdnihall?hl=en to shorten them to a list and export the URL's as a text file
  3. In a text editor shorten the URL's to just the last part (username/repositoryname)
  4. Create a new personal API token with capability to delete repositories and paste that token in the script
  5. Run ./clean-repos.sh

Enjoy your cleaned up Github account!

#!/bin/bash
filename='repos.txt'
api_token='YOUR_TOKEN_HERE'
echo Start
while read p; do
echo Deleting: $p
curl -X "DELETE" -H "Authorization: token ${api_token}" https://api.github.com/repos/$p
done < $filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment