Carles Andres' avatarHomeBlog

Cleaning up my GitHub account from old repos

I recently realised I had a lot of junk in my GitHub account. Over the years, I have gathered forks and abandoned projects that I had completely forgotten about.

I've been using the GitHub CLI more and more over the years, and it's turned out to be a great help on this occasion.

The first thing I've done is figure out how big my problem was.

Running gh repo list turned up a staggering 160 projects!! I can assure you I'm not maintaining that many projects at all.

gh repo list screenshot

NOTE

I'm assuming you have already used gh before, and that you have already logged in with your GitHub account.

If you haven't, start by installing it with brew install gh and then login with gh auth login.

I decided to start by archiving all projects that were forks, but I still wanted to figure out one by one if they were worth keeping, so I listed them all using:

gh repo list --fork --no-archived

Once I have chosen a project to archive, say my-repo, I can then just call:

gh repo archive carlesandres/my-repo -y

where the -y avoids having to confirm the archival.

Automating

You can obtain a list of, say, just the unarchived repo names with a command like:

gh repo list --no-archived --json nameWithOwner -q '.[].nameWithOwner'

This could then be passed to fzf for selection and take an action, for example: archive, on the list of selected repo names. But I'm leaving that for another day.

Cleaning up my GitHub account from old repos