A collection of Python scripts to manage your GitHub repositories: delete forks, make repositories private, and detach from fork networks.
- Python 3.9.7
- PyGithub library
- requests library
-
Clone or download this repository
-
Install dependencies:
pip install PyGithub requestsOr if using a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install PyGithub requestsAll scripts require a GitHub Personal Access Token with appropriate permissions.
- Go to https://github.com/settings/tokens
- Click "Generate new token (classic)"
- Select required scopes:
- ✅
repo(required for all scripts) - ✅
delete_repo(required for delete_forks.py only)
- ✅
- Copy the generated token
- Replace
"your_github_token_here"in each script with your token
📖 Need detailed instructions? See HOW_TO_GENERATE_GITHUB_ACCESS_TOKEN.md for a complete step-by-step guide with troubleshooting tips and security best practices.
Open each script and replace the placeholder token:
TOKEN = "your_github_token_here" # Replace with your actual tokenDeletes all forked repositories from your GitHub account.
Usage:
python delete_forks.pyWhat it does:
- Lists all forked repositories in your account
- Shows repository names, URLs, and privacy status
- Asks for confirmation before deleting
- Deletes all forks after typing
DELETE ALL FORKS
Required Token Permissions:
repodelete_repo
Makes all public repositories private.
Usage:
python make_repos_private.pyWhat it does:
- Lists all public repositories
- Separates forks from non-forks
- Makes non-fork repositories private
- Skips public forks (GitHub limitation: public forks cannot be made private)
Note: Public forks cannot be converted to private repositories due to GitHub's policy. To make a public fork private, you must delete it and recreate it as a new private repository.
Required Token Permissions:
repo
Detaches forks from their parent network and attempts to make them private.
Usage:
python remove_to_fork_network.pyWhat it does:
- Finds all forked repositories
- Detaches them from the fork network using GitHub's GraphQL API
- Attempts to make them private
- Shows helpful error messages if conversion fails
Note: Even after detaching, GitHub still doesn't allow public forks to be made private. This script will inform you which repositories need manual intervention.
Required Token Permissions:
repo
Your token is invalid or expired. Generate a new token and update the scripts.
Your token doesn't have the delete_repo scope. Update your token permissions.
This is a GitHub limitation. To convert a public fork to private:
- Delete the fork
- Create a new private repository
- Push your code to the new repository
All scripts include:
- ✅ Preview of what will be affected
- ✅ Confirmation prompts before destructive actions
- ✅ Detailed progress reporting
- ✅ Error handling with helpful messages
- ✅ Summary statistics after completion
To clean up your GitHub account:
-
Delete all forks:
python delete_forks.py
-
Make remaining repos private:
python make_repos_private.py
These scripts were developed and tested with:
- Python 3.9.7
- PyGithub 2.x
- macOS (but should work on Windows/Linux)
Free to use and modify for your own purposes.
- Review the preview before confirming
- Ensure you have backups of important code
- Test with a few repositories first if unsure
- Double-check which repositories will be affected
The author JLBardinas is not responsible for any data loss resulting from the use of these scripts.