Skip to content

Instantly share code, notes, and snippets.

@heroqu
Created January 6, 2016 18:03
Show Gist options
  • Select an option

  • Save heroqu/c7704535d74c0e66d60b to your computer and use it in GitHub Desktop.

Select an option

Save heroqu/c7704535d74c0e66d60b to your computer and use it in GitHub Desktop.
Bash script for bulk deletion of repos under your github account
#! /bin/bash
## Based on and inspired by
# https://medium.com/@icanhazedit/clean-up-unused-github-rpositories-c2549294ee45
## Vars
# 1. Your github user name
USERNAME=john
# 2. Token with delete_repo priviledge
# to obtain token just go to your github account to the page
# https://github.com/settings/tokens/new
# ( don't forget to check 'delete_repo' checkbox before generating )
# put the token string here between single quotes instead of x-es.
TOKEN='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# 3. List of repos to be deleted.
# - plain text file in the same directory as this script with one repo name per line
# (don't put fully qualified repo names, just the part after last slash).
# Change the file name here if the file is named differently.
REPO_LIST_FILE='./repolist.txt'
## Get rid of that crap
cat ${REPO_LIST_FILE} | xargs -I {} curl -X DELETE -H "Authorization: token ${TOKEN}" https://api.github.com/repos/${USERNAME}/{}
## PS.
# The blog post mentioned in the beginning explaines how to make a list of your github repos in a easier way using Chrome browser extention.
# This can really help if you need to delete dozens of repos (stale forks e.g.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment