Cleaning Up Your Github Repos


I was recently reduced from the staff of the Flatiron School and, after my GitHub accounts were terminated, I still had a ton of repos that had been forked from the company’s accounts to my own. The GitHub web UI doesn’t help with bulk actions, so I scripted it.


  1. Use hub's low-level API to generate a death list in a file
  2. Peruse the file
  3. Feed the file into hub to do the deletion

Use hub's Low-level API to Generate a Death List in a File

Inspired by the information in rmkpatchaa‘s Gist, I took the hub program and used its low-level API + jq to generate a list of my repos:

Due to rate limits, etc. I proceeded in 100-repo chunks:

hub api "/users/sgharms/repos?per_page=100&affiliation=owner&page=1" |jq '.[] | .name' >> killnames

hub api is built to emulate the API of the curl program. So if you’re familiar with those flags, you’re going to be very comfortable. Notably, it uses -H for headers and -X to change HTTP verbs. The data that are returned were copious, so we use parameters and our friend jq to winnow things down to the list of repo names. We accumulate those names into the file killnames using the redirect-and-append.

Peruse the File

Depending on how many repos you created, you might need to do a lot of work here; or, maybe, it won’t be so bad. I used vim to winnow down this population. Deletion is a pretty drastic step and I didn’t want to mess it up. The verb peruse is the right one to do here.

Leveraging vim’s g/regex-of-thing-to-delete/d made short work of some of the copied-by-bulk algorithm names.

Feed the File Into hub to Do the Deletion

Now comes the fun part. Ask hub api to delete for you:

while read r; do echo $r; hub delete $r; done < killnames

This will iterate through the repos and ask you to confirm deletion.

But since we carefully perused our killnames file, I added the -y flag after delete to terminate with extreme prejudice.

Kill it with fire


This got me back down to a very livable forty living repos.