Delete all unused repositories and forgotten forks in 6 (semi)-automatic steps!

Can I Haz Edit
Jul 22, 2014 · 2 min read

Ugh. Github forces me to type my password for every fork and repository I want to delete. That’s smart and all, but what if one wants to mass-delete a bunch of old, unused, forgotten, dirty little repositories that make his repository list look like a mess? well, that person follows this short guide:

  1. Open in a new tab all to-be-deleted github repositores (Use the mouse’s middle click) https://github.com/wildeyes?tab=repositories
  2. Use one tab https://chrome.google.com/webstore/detail/onetab/chphlpgkkbolifaimnlloiipkdnihall?hl=en to shorten them to a list.
  3. Save that list to to a file, and modify each entry so that it’s in the form of “ur_username/repo_name” per line, (not a full URL!). Use multiple cursors /selections for the quickest results with an advanced text editor such as VS Code or sublime (double click a word, then ctrl-d or alt-f3 to have multiple selections).
  4. Register a new personal access token with a delete_repo permission at this address https://github.com/settings/tokens/new
  5. Use the line appropriate for your operating system below, replacing UR_TOKEN with your access_token.
  6. L̶i̶n̶u̶x̶:̶ ̶t̶h̶e̶ ̶a̶c̶u̶t̶e̶ ̶(̶a̶n̶d̶ ̶t̶h̶o̶u̶g̶h̶t̶f̶u̶l̶)̶ ̶r̶e̶a̶d̶e̶r̶ ̶w̶i̶l̶l̶ ̶u̶s̶e̶ ̶a̶ ̶c̶o̶m̶b̶i̶n̶a̶t̶i̶o̶n̶ ̶o̶f̶ ̶x̶a̶r̶g̶s̶ ̶+̶ ̶c̶u̶r̶l̶,̶ ̶a̶n̶d̶ ̶o̶n̶c̶e̶ ̶d̶o̶n̶e̶ ̶w̶i̶l̶l̶ ̶t̶w̶i̶t̶ ̶t̶h̶e̶ ̶l̶i̶n̶e̶ ̶h̶e̶ ̶u̶s̶e̶d̶ ̶t̶o̶ ̶@̶x̶w̶i̶l̶d̶e̶y̶e̶s̶. O̶S̶ ̶X̶:̶ ̶t̶h̶e̶ ̶s̶a̶m̶e̶ ̶l̶i̶n̶e̶ ̶f̶o̶r̶ ̶L̶i̶n̶u̶x̶ ̶s̶h̶o̶u̶l̶d̶ ̶w̶o̶r̶k̶ ̶f̶o̶r̶ ̶y̶o̶u̶ ̶g̶u̶y̶s̶ ̶t̶o̶o̶.̶
    OSX + Linux: (Thanks to @whitjck from twitter)
while read repo; do curl -X DELETE -H "Authorization: token UR_TOKEN" "https://api.github.com/repos/$repo"; done < repos.txt

7. Windows: Run in powershell:

get-content D:\repolist.txt | ForEach-Object { Invoke-WebRequest -Uri https://api.github.com/repos/$_ -Method "DELETE" -Headers @{"Authorization"="token UR_TOKEN"} }

Can I Haz Edit

Written by

Random Internet Ramblings — Web Development, Linux, Building Products and Startups, some philosophical ponderings.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade