GitHub: Script to Mass Delete Repos

Delete GitHub repositories programmatically from a CSV file


If you’ve ever had to delete several repositories in GitHub, you know it can be a pain as you have to copy/paste the name of each repo in the verification prompt. This script aims to simplify that by providing a list of repositories that you want to delete in a CSV, and then looping through each repo and deleting it with the gh cli.

The Scripts

These scripts are in my github-misc-scripts repo:

Using the Scripts


  • You need to make sure to have the gh cli installed and authorized (gh auth login).
  • Add the delete_repo scope:
    gh auth refresh -h -s delete_repo


  1. Prepare a list of repositories that you want to delete and place in a CSV file, one per line, with the last line empty.
    • You can use the script to generate a list of repos in a GitHub org, and then modify accordingly:
      ./ joshjohanning-org > repos.csv
    • Or, create your own CSV file with the list of repos you want to delete, one per line, and leave a trailing empty line/whitespace at the end of the file. The file should look like:
  2. From there, it’s pretty simple - run the script, passing in the repos.csv file:
     ./ repos.csv


If you accidentally delete a repository that you didn’t mean to, the good news is that you have 90 days to recover it in most cases (with some caveats for forks).

Hopefully this script saves you some time in the UI copy/pasting repo names when you want to do some spring cleaning!

This post is licensed under CC BY 4.0 by the author.