How to Delete multiple GitHub repositories at once ?


👤 Diwas Poudel    🕒 Nov 24 2022    📁 FIX

You may have built numerous repositories when experimenting with creating projects in Github to learn git and version control. And after a few months or years, you may have decided to delete some or all of the repositories, so you may have tried deleting them one by one by clicking on your desired repository, then going to settings, and finally clicking on Delete this repository, as seen below.

Deleting Single Repo
fig. Deleting Single Repo 😅

This is okay if you only have a few repositories. What to do if you have to delete 20-30 repositories. If this is what you are thinking, you have come to the right place. Ourtechroom will help you delete multiple repositories using various methods.

Delete multiple repos from Github

How to Delete Github Repository
How to Delete Github Repository
Let's look at two of them.

Method 1: Using Reposweeper Tool

RepoSweeper is a React.js-based utility that allows you to sort, filter, and control which repositories you want to delete at scale with just a single or few clicks of a button.

The steps are as follows:

1. First get the username of the GitHub repository

Log in to your GitHub account. Then, in the top right corner, click the Profile icon. Then, from the list of options, select Your Profile.

Get your Github Username
fig. Get your GitHub Username

Then, in three places, you will discover your Github username ie. in the URL, immediately below your FullName, and in the menu from which you arrived at the profile page.

In my case, GitHub username is: Diwas777

Get Github Username in 3 places
fig. Github Username

2 Goto reposweeper site by clicking here. 

3 Scroll down to find the Username and Token Field.

Copy and paste your Username, in my case Diwas777, then click Generate Access Token.

Goto Reposweeper Tool Home Page
fig. Reposweeper Tool

This will redirect you to your Github with the URL: https://github.com/settings/tokens.

4 Click on the "Generate new token" button just next to the Personal access token(classic).

5 From the list click on Generate new token(Classic).

Click on Generate new token button
fig. Generate new Token

6 Give the Note a name, then scroll down and check the ☑ delete repo checkbox, and then click on Generate Token button.

📚 Take note that we have granted remove repo 
This will generate github token
fig. Generate Token Github

7 Just click on the Windows icon next to the token. This will copy the token to the clipboard.

Copy Token to clipboard
fig. Copy Token to clipboard

8 Now Come back to RepoSweeper and paste down the token in the token field and click on the "Generate Repo List" button.

Paste token to reposweeper and click on Generate Repo List
fig. Paste the token in reposweeper and click on 'Generate repo list'

9 Then wait for some time, you will get all your repository present in your GitHub.

Simply click the topmost checkbox to delete the entire repository. Otherwise, choose all of the checkboxes next to your git repo and then click the Delete button.

Also read: HTTPS vs SSH in git 

Here I want to delete that 5 repo so I have selected then click on the Delete button as shown below.

Select Repo you want to delete
fig. Select Repos you want to delete

10 Now on the next screen click on the Continue button.

Continue to delete repo
fig. Continue to delete the repo

11 In the next screen, you will get a confirmation like Are you sure you want to delete those selected repos? Just click on the Delete button.

Click on 'Delete' button in confirmation page
fig. Click on the 'Delete' button on the confirmation page

Return to your GitHub and refresh the page. You will not find those deleted repositories.

Method 2: Using the Terminal and command line

First create a list of the repo you want to delete in the form of “your_username/repo_name” (not a full path of the repo) per line like shown below and save it into a file let's say: repo_to_delete.txt 

Linux and macOS

Then if you are in Linux or macOS then run the below command.

while read repo; do curl -X DELETE -H "Authorization: token YOUR_TOKEN_HERE" "https://api.github.com/repos/$repo"; done < repo_to_delete.txt

Windows and Powershell

If you are in Windows then open PowerShell and run the below command and click Enter.

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

In windows, I have placed those repo inside the repo_to_detele.txt file inside E drive.

Using Bash 

Here, we list all of the repos that we want to delete within a variable called repo to delete, and we loop through each of these data, authorizing each of the repos with the token, and then deleting them. Curl is a command-line program that allows us to send requests from clients to servers.

Note that you have to pass your GitHub token in the placeholder YOUR_TOKEN_HERE.

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

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

👊 MORE FROM OURTECHROOM 👊



Ourtechroom Main Logo
Hello and thank you for visiting Ourtechroom.com! We'll talk about everything from how to troubleshoot tech issues, to emerging technology, games, gadgets, and fun facts about technology.
Contact : ourtechroom777@gmail.com