This script allows you to delete multiple repositories from your GitHub account using a personal access token (PAT).
To use this script, you'll need to generate a personal access token (PAT) on GitHub. Follow these steps to generate the token:
-
Navigate to GitHub Settings: Go to the Settings page of your GitHub account.
-
Access Developer Settings: In the Settings page, scroll down the left sidebar and click on "Developer settings".
-
Generate New Token: Under Developer settings, click on "Personal access tokens".
-
Choose Classic Tokens: Click on the second option, "Tokens (classic)".
-
Generate New Token: Click on the "Generate new token" button.
-
Provide Token Description: Enter a description for the token.
-
Select Scopes: Choose the scopes (permissions) for the token. You'll likely need permissions related to repositories, such as
repo
(Full control of private repositories) anddelete_repo
(Delete repositories). -
Generate Token: Click on the "Generate token" button.
-
Copy Token: Once the token is generated, copy the token value and store it securely.
-
Use Token: In your script or application, use this token as the auth parameter when authenticating with the GitHub API.
-
Keep Token Secure: Treat your personal access token like a password and do not share it with anyone or expose it in public repositories.
To install dependencies, run:
npm install
After installing the script, you need to create a config.js
file with your GitHub personal access token and username. You can use the provided sample.config.js
as a template:
- Copy
sample.config.js
toconfig.js
. - Open
config.js
in a text editor. - Replace
GITHUB_PERSONAL_ACCESS_TOKEN
with your actual GitHub personal access token. - Replace
GITHUB_USERNAME
with your GitHub username. - Save the file.
Make sure to keep your personal access token secure and do not share it with anyone or expose it in public repositories.
To delete repositories, run the script:
npm run delete-repos
-
-y
or--yes
: Skips the prompt confirmation before deleting repositories.
npm run delete-repos -- -y
-
--except
: Deletes all repositories except those listed in the specified file. Each repository name should be listed on a separate line in the file.
npm run delete-repos -- --except 'github-repo-delete/excluded_repos.txt'