Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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 :)

@adamvoss
Copy link

adamvoss commented Mar 11, 2018

Here is a variation on @bartoszmajsak's solution that uses curl instead of httpie to delete all repositories from an organization.

curl -u $USERNAME:$PASSWORD https://api.github.com/orgs/$ORG/repos | jq '.[].full_name' | tr -d '\r' | xargs -I '{}' curl -u $USERNAME:$PASSWORD -XDELETE https://api.github.com/repos/'{}'

@timdams
Copy link

timdams commented Mar 15, 2018

Great tip. Works in windows, but you might need to first run the following command in powershell (otherwise you might get an "can't create ssl/tls channel"exception)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

@joesasson
Copy link

joesasson commented May 15, 2018

Awesome!! Really helped me!
Something I encountered was that certain repos had titles after the repo path.
The regex wasn't working for VScode, so what I did was paste into google sheets (will work in excel also) and split by : then just pasted the first column into my final file.

@AmitaiB
Copy link

AmitaiB commented Aug 24, 2018

Anybody know a way to bulk private-ize my repos?

@andybeak
Copy link

andybeak commented Nov 4, 2018

The solutions above didn't work for me, so I approached this with https://gist.github.com/andybeak/602611212950559df9c102b0d1ae20c7
It works on Linux without needing jq or httpie. A bit hacky because it's hard coded to the current output format, but I don't do this task often enough to merit spending time on writing a beautiful automation script.

@deignorated
Copy link

deignorated commented Dec 11, 2018

Thank you!

@aug2uag
Copy link

aug2uag commented Jan 7, 2019

your method worked for me, here's how I ended up implementing it

#!/bin/bash

repos=(
	"username/repo1"
	"username/repo2"
	"username/repo3"
)

for i in "${repos[@]}"
do
   : 
   curl -XDELETE -H 'Authorization: token XXX' "https://api.github.com/repos/$i ";
done

@moollaza
Copy link

moollaza commented Apr 1, 2019

In case anyone is interested, I built a little web app that helps you delete (or archive) multiple GitHub repos. It displays all your repos, and allows you to sort/filter them, and select which ones you want to modify. Under the hood, it just uses the GitHub API and an access token you provide.

You can try it out to at https://reporemover.xyz/.

It’s also open source, and available on GitHub.

@DavidGriswoldTeacher
Copy link

DavidGriswoldTeacher commented May 14, 2019

In case anyone is interested, I built a little web app that helps you delete (or archive) multiple GitHub repos. It displays all your repos, and allows you to sort/filter them, and select which ones you want to modify. Under the hood, it just uses the GitHub API and an access token you provide.

You can try it out to at https://reporemover.xyz/.

It’s also open source, and available on GitHub.
@moollaza
I love this, but it doesn't give me a way to select repositories on organizations I have admin rights to. Any way to add that?

@moollaza
Copy link

moollaza commented May 15, 2019

I love this...

Thanks for the feedback @DavidGriswoldTeacher. I'm glad to hear you like RepoRemover!

but it doesn't give me a way to select repositories on organizations I have admin rights to. Any way to add that?

There's actually an open issue already to add this. I spent a few minutes looking into it and I think it's possible, however when I was testing using the API, I couldn't get it to work. I'll have to spend more time investigating to see if its possible, but I expect it should be.

@singchan
Copy link

singchan commented Jun 20, 2019

Thx for the tip
For those who need to delete with a visual interface I use this online demo of cloud explorer, you can very quickly delete many repos
http://cloud-explorer.org/

@thall1961
Copy link

thall1961 commented Jul 30, 2019

@moolaza that's awesome just deleted like 70 repos! Upvoted!

@politician
Copy link

politician commented Nov 7, 2019

I have made a Node.js CLI that lets you bulk publicize, privatize, clone and/or delete repos for a personal Github account or an organization.
https://github.com/incorrupt/bulkrepos
It should be helpful at least to the people who want to backup their repos before deleting them :)

@janosh
Copy link

janosh commented Dec 4, 2019

Just tried out RepoRemover. Works great! Thanks @moollaza!

@learning2016
Copy link

learning2016 commented Dec 29, 2019

Any of the above methods
I want to know
How do I remove Organizations' repositories in bulk
thank you!

@moollaza
Copy link

moollaza commented Dec 29, 2019

@janosh you're welcome! I'm glad to hear it was useful :)

@learning2016 you can easily remove Org repos in bulk with https://reporemover.xyz

@FrancisCalizo
Copy link

FrancisCalizo commented Jan 10, 2020

@moollaza You're awesome! Thanks!

@nk23x
Copy link

nk23x commented Mar 2, 2020

thanks :)

@ingnelson
Copy link

ingnelson commented Jul 18, 2020

@moollaza thanks , it works for me

@ahmetcetin
Copy link

ahmetcetin commented Jan 3, 2021

@mooliza kudos, you saved hours of work!

@jayanth0107
Copy link

jayanth0107 commented Mar 1, 2021

@mooliza awesome !! you have created a website that github won't provide

@renanalencar
Copy link

renanalencar commented Jun 3, 2021

@janosh you're welcome! I'm glad to hear it was useful :)

@learning2016 you can easily remove Org repos in bulk with https://reporemover.xyz

Very good indeed.

@oneezy
Copy link

oneezy commented Jul 11, 2021

Repo Remover FTW !!!

https://reporemover.xyz

@XavierTolza
Copy link

XavierTolza commented Sep 11, 2021

Or also with python3+:

pip install git+https://github.com/XavierTolza/PyGithubRepoDeleter.git
remove_github_repos --token <your token>

image

@onursagir
Copy link

onursagir commented Dec 13, 2021

I've also written a small Node application that requires no installation, simply running npx bulk-delete-repo should do the trick

@dawesi
Copy link

dawesi commented Apr 19, 2022

Repo remover only does personal repos not orgs :-(

@moollaza
Copy link

moollaza commented Apr 20, 2022

Repo remover only does personal repos not orgs :-(

@dawesi, org repos should be supported. Do you have permissions to edit the repos in the org? Alternatively, are they private org repos?

If they are private, there is an open PR I need to review which should add support for those

Edit:
I've deployed the PR with support for Private Org repos here: https://repo-remover-op56z4vb4-moollaza.vercel.app/
The PR with the change is here for anyone interested: moollaza/repo-remover#182

@luigi-smilzo
Copy link

luigi-smilzo commented Apr 30, 2022

In case anyone is interested, I built a little web app that helps you delete (or archive) multiple GitHub repos. It displays all your repos, and allows you to sort/filter them, and select which ones you want to modify. Under the hood, it just uses the GitHub API and an access token you provide.

You can try it out to at https://reporemover.xyz/.

It’s also open source, and available on GitHub.

Very, very, very helpful. Thank you!

@airtonix
Copy link

airtonix commented Oct 30, 2022

http https://api.github.com/user/repos "Authorization:token $GITHUB_TOKEN" per_page==100 type==owner \
    | jq '.[] | .full_name' \
    | fzf -m \
    | xargs -I '{}' http DELETE https://api.github.com/repos/'{}' "Authorization:token $GITHUB_TOKEN" 

needs:

  • jq
  • httpie
  • fzf
Screencast.from.30-10-22.16.20.09.webm

tweak this part to customise the query

    | jq '.[] | .full_name' \

so if you want to only list repos that are a fork and is a template repo:

    | jq '.[] | select(.fork==true) | select(.is_template==true) | .full_name' \

more info on the repo object here: https://docs.github.com/en/rest/repos/repos#list-repositories-for-the-authenticated-user

@infr
Copy link

infr commented Nov 4, 2022

For deleting organization team repos

  1. Generate a personal access token with 'delete_repo' permission: https://github.com/settings/tokens/new
  2. Open the teams repositories view and run following in the browsers console
let repos = ''
const el = document.querySelectorAll('#org-team-repositories > ul > li > div:nth-child(1) > div > div:nth-child(2) > a > span').forEach(e => {repos = repos + `"${e.innerText}"\n`})
console.log(repos)
  1. Copy paste the output to @aug2uag shell script and run it (fixed extra space typo in it):
#!/bin/bash

repos=(
	"username/repo1"
	"username/repo2"
	"username/repo3"
)

for i in "${repos[@]}"
do
   : 
   echo 'Delete' "$i";
   curl -XDELETE -H 'Authorization: token XXXX' "https://api.github.com/repos/$i";
done

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