Skip to content

Instantly share code, notes, and snippets.

@mrkpatchaa
Last active October 21, 2024 16:46
Show Gist options
  • Save mrkpatchaa/63720cbf744a2bf59a3e9cfe73fc33b0 to your computer and use it in GitHub Desktop.
Save mrkpatchaa/63720cbf744a2bf59a3e9cfe73fc33b0 to your computer and use it in GitHub Desktop.
Bulk delete github repos

Use this trick to bulk delete your old repos or old forks

(Inspired by https://medium.com/@icanhazedit/clean-up-unused-github-rpositories-c2549294ee45#.3hwv4nxv5)

  1. Open in a new tab all to-be-deleted github repositores (Use the mouse’s middle click or Ctrl + Click) https://github.com/username?tab=repositories

  2. Use one tab https://chrome.google.com/webstore/detail/onetab/chphlpgkkbolifaimnlloiipkdnihall to shorten them to a list.

  3. Save that list to some path

  4. The list should be in the form of “ur_username\repo_name” per line. Use regex search (Sublime text could help). Search for ' |.*' and replace by empty.

  5. Register a new personal access token with a 'delete_repo perm' https://github.com/settings/tokens/new

  6. Copy the access_token and run the following line replacing xxx with your access token.

Linux and OS X :

while read r;do curl -XDELETE -H 'Authorization: token xxx' "https://api.github.com/repos/$r ";done < repos

Windows:

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

Caution

I have only tested this script on Linux.

Have fun :)

@Chris-McQuiggan
Copy link

Chris-McQuiggan commented Aug 29, 2024

@moollaza

I am generating the token from your link but the reporemover is telling me that the token is invalid? My tokens all start with ghp_ but reporemover is telling me they are invalid because of the underscore. Thoughts?

For anyone who has this issue, I had to add "Bearer " to mine and it worked -> Authorization: Bearer ghp_xxx or -Headers @{"Authorization"="Bearer ghp_xxx"}

@MYGguy
Copy link

MYGguy commented Sep 4, 2024

Wow! I used reporemover.xyz and it worked like a charm. Thank you @moollaza!

@fletort
Copy link

fletort commented Oct 9, 2024

I you want to delete all repo of an organization (in my case i have a personal org dedicated to some test) :
gh repo list my-org-name | sed -e 's/\s.*//' | xargs -L1 gh repo delete --yes

@raze-raptor
Copy link

Worked FLAWLESSLY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment