Skip to content

Instantly share code, notes, and snippets.

@randomradio
Created April 11, 2018 22:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomradio/fb567fecd32e8fdce61602a311c0d19f to your computer and use it in GitHub Desktop.
Save randomradio/fb567fecd32e8fdce61602a311c0d19f to your computer and use it in GitHub Desktop.
batch remove github repository

Bulk delete repositories, keep your github sane and remind you how many undone project you hoarded.

Delete all repos

  1. repos.txt contains a list of repository names in {UserName}/{RepoName} format, e.g. IanZhao/to-be-deleted. use this file to track all repositories you want to delete.
  2. Open fetchSaveRepo.js and update url with your github username.
  3. you need node-fetch to fetch contents, just do a npm init with default settings and run npm install node-fetch.
  4. run node fetchSaveRepo.js
  5. Generate a Authorization Token for repo delete access token
  6. Copy the token and put in in place TOKEN_HERE in deleteRepos.sh
  7. If you certain, run ./deleteRepos.sh.
while read r; do
echo "https://api.github.com/repos/$r"
curl -XDELETE -H 'Authorization: token TOKEN_HERE' "https://api.github.com/repos/$r";
done < repos.txt
const fetch = require('node-fetch');
const fs = require('fs');
const path = 'repos.txt';
const repoUrl = 'https://api.github.com/users/{username}/repos?per_page=200';
const logger = fs.createWriteStream(path, {
flags: 'a',
});
const fetchRepos = (url = 'https://api.github.com/users/{username}/repos?per_page=200') => {
fetch(url)
.then(reply => reply.json())
.then((results) => {
results.map((repo) => {
console.log(repo.name);
const name = `${repo.full_name}\n`;
logger.write(name);
return true;
});
})
.then(() => logger.end())
.catch(err => console.log(err));
};
fetchRepos(repoUrl);
# IanZhao/repo-to-delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment