This script automates the process of deleting forked repositories from your GitHub account using the GitHub API. It ensures that only forked repositories are deleted, leaving your original repositories untouched.
- ✅ Lists all repositories in your GitHub account
- ✅ Identifies forked repositories
- ✅ Deletes only forked repositories (your original repositories are safe)
- ✅ Uses the GitHub API for authentication and deletion
- ✅ Supports pagination to fetch all repositories
This script requires the requests
library. If you don't have it installed, run:
pip install requests
To authenticate with the GitHub API, generate a PAT with the necessary permissions:
- Go to GitHub Personal Access Tokens
- Click "Generate new token (classic)"
- Set an expiration date or choose "No expiration"
- Select the following permissions:
- ✅
delete_repo
(to delete repositories) - ✅
repo
(to access your repositories)
- ✅
- Click Generate Token and copy it (you won't see it again!)
Replace your-username
and your-personal-access-token
in the script:
GITHUB_USERNAME = "your-username"
GITHUB_TOKEN = "your-personal-access-token"
Alternatively, you can store the token securely using environment variables:
export GITHUB_TOKEN="your-token-here"
Modify the script to fetch the token:
import os
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")
Execute the script with:
python delete_forks.py
- This action is irreversible – once a forked repo is deleted, it cannot be recovered.
- Ensure you have the correct permissions before running the script.
- The script only deletes forked repositories (not your original ones).
This script is open-source and provided as-is without warranty. Feel free to modify and use it at your own risk.
If you encounter issues, feel free to open a discussion or reach out! 🚀