Skip to content

Instantly share code, notes, and snippets.

@Ragdata
Created November 14, 2022 05:17
Show Gist options
  • Save Ragdata/f5a7a0769639e64b778cf43ba4923787 to your computer and use it in GitHub Desktop.
Save Ragdata/f5a7a0769639e64b778cf43ba4923787 to your computer and use it in GitHub Desktop.
Bulk Delete Old Github Repos & Forks

Bulk Delete Old Github Repos & Forks

(Inspired by the resources listed at the bottom of this Gist)

Deleting old repos in bulk is quite easy if you've got a WSL instance at hand.

Step 1 - Create Your Hitlist

Open a text editor, and list each repository you want to delete in the form of userName\repoName with one per line.

Because this is a regex search, you'll want to replace any spaces with wildcards (.*):

ragdata\old-repo-one
ragdata\old.*repo-two

Save that file somewhere you won't lose it.

Step 2 - Create a New Personal Access Token

Open a browser to Github and create a new personal access token for yourself. You'll need the delete_repo permission (see https://github.com/settings/tokens/new)

Once you've got your access token, copy it to your clipboard and execute the following command under a WSL terminal:

export TOKEN="<paste your token here>"
export HITLIST_PATH="<path to the file you saved above>"

Step 3 - Never be Caught Short Again

So that you don't forget this snippet too quickly, stick it in your .bash_functions file so that you can use it anytime:

gitBulkDelete() {
    while read r;
    do
        curl -XDELETE -H 'Authorization: token "$TOKEN"' "https://api.github.com/repos/$r "
    done < "$HITLIST_PATH"
}

Step 4 - Execute!

Now all you need to do is execute your function. Don't forget to source your .bash_functions file if you haven't before now:

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