This script, repo-cleaner
, will delete every repository matching a specific pattern for either a user or organization based on options passed through the command line. This solves the problem many of us experience when doing testing where multiple repositories are created and need to be deleted after the testing/debugging is finished.
Before running this script, you must create a Personal Access Token (PAT) (see: creating a personal access token for more info) with the permissions <repo>
and <delete_repo>
scopes. You can read more about Scopes for OAuth Apps here. Once created, you must export your PAT as an environment variable named <GITHUB_TOKEN>
.
- Exporting PAT as
GITHUB_TOKEN
export GITHUB_TOKEN=abcd1234efg567
repo-cleaner - Deletes every repository matching a specific name pattern for the user or org specified up to 30 at a time
repo-cleaner [-o=<org_name>] [-u=<username>] [-s=<string-to-match-against>]
Deletes every repository for the user (if -u=<username>
is used) or for an organization (if -o=<org_name>
is used instead) that matches the string (specified by -s=<string-to-match-against>
). If -s
is omitted it will list the repos available to delete instead. Will delete up to 30 repositories with every execution due to default pagination.
--org
| -o
When running the tool, this flag sets the API endpoint to point to an organization (specififed by -o=<org_name>
), deleting the repos that match the given string from -s
(see below).
- NOTE: Can NOT be used with the
-u
option.
--user
| -u
When running the tool, this flag sets the API endpoint to point to a user (specified by -u=<username>
), deleting the repos that match the given string from -s
(see below).
- NOTE: Can NOT be used with the
-o
option.
--string
| -s
When running the tool, this flag sets the string to match against the name of the repo(s) you are wanting to delete. If omitted will list repositories for given user or organization (specified by -u=<username>
or -o=<org_name>
) without deleting any.
- Lists repos under user account
IAmHughes
that are available to be deleted.
bash repo-cleaner -u=IAmHughes
- Deletes repos under org
TheBeardedTom
that are namedTest_Repo_
- For example:
Test_Repo_
,Test_Repo_qa
,Test_Repo_234
, etc. would be deleted.
- For example:
bash repo-cleaner -o=TheBeardedTom -s=Test_Repo_
- Deletes repos under user
IAmHughes
that are namedMyRepo
- For example:
MyRepo
,MyRepo1
,MyRepo99
,MyRepoQA
, etc. would all be deleted.
- For example:
bash repo-cleaner -u=IAmHughes -s=MyRepo
All documentation can be found at the GitHub Developer Docs page.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- Thomas Hughes - Maintainer / On-Going Support - @IAmHughes
- Michael Johnson - Initial Work - @Migarjo
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to @Migarjo for the initial base for the script.