How to Delete Github Repository Quickly

I did some spring-cleaning on my Github repositories a few days ago.

I was doing it manually at first, by going through the repository settings page, clicked on the delete button in the Danger Zone section, went through several popups and finally entered the repository name to confirm the deletion. Yeah… it’s such a boring chore.

Then, I remembered that Github has a cli client that I have been using for creating repo and pull requests. Figured I might take a look again at their docs to see if there’s a command for deleting a repository or setting a repository to private, and there is one! The usage is simple too. Here’s how.

Install gh

If you don’t have it install yet, simply run the following command:

brew install gh

Once that’s done, run the following command to authenticate with Github:

gh auth login

To delete a repository

To delete a repository, run the following command

# add --yes to confirm deletion without prompting
gh repo delete $REPO --yes

To change from public to private repository

To modify repository access, run the following command:

gh repo edit $REPO --visibility=private

Replace $REPO with the repo name. You can use either the full URL or the repo name. For example.

# to delete using url
gh repo delete https://github.com/faizmokh/dummyrepo

# to modify access using repo name
gh repo edit faizmokh/dummyrepo --visibility=private

That’s all. Go through the docs, if you want to know what else you can do with gh

References:

  1. gh cli documentation