Skip to content

Bulk delete forked repos, leaving your original repositories untouched.

License

Notifications You must be signed in to change notification settings

fd2013/bulk_delete_forked_repos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

🗑️ GitHub Forked Repo Deletion Script

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.


🚀 Features

  • ✅ 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

🔧 Prerequisites

1️⃣ Install Python Dependencies

This script requires the requests library. If you don't have it installed, run:

pip install requests

2️⃣ Generate a GitHub Personal Access Token (PAT)

To authenticate with the GitHub API, generate a PAT with the necessary permissions:

  1. Go to GitHub Personal Access Tokens
  2. Click "Generate new token (classic)"
  3. Set an expiration date or choose "No expiration"
  4. Select the following permissions:
    • delete_repo (to delete repositories)
    • repo (to access your repositories)
  5. Click Generate Token and copy it (you won't see it again!)

🛠️ Usage

1️⃣ Set Up Authentication

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")

2️⃣ Run the Script

Execute the script with:

python delete_forks.py

⚠️ Warning

  • 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).

📝 License

This script is open-source and provided as-is without warranty. Feel free to modify and use it at your own risk.


📬 Need Help?

If you encounter issues, feel free to open a discussion or reach out! 🚀