A modular Python tool to archive, make private, or delete repositories from your GitHub account using the GitHub API.
- Archive repositories (recommended, safest)
- Make repositories private (recommended for sensitive code)
- Delete repositories (dangerous, irreversible—use with extreme caution)
- Preserve list: Exclude repositories by name or regex pattern
- Export repository list to CSV
- Comprehensive logging (to both console and
logs/cleanup.log
) - No secrets stored on disk: Uses
GITHUB_TOKEN
environment variable
-
Clone the repository:
git clone https://github.com/your-username/github-repositories-cleanup.git cd github-repositories-cleanup
-
Install dependencies:
pip install -r requirements.txt
-
Set your GitHub token as an environment variable:
- On Windows (Command Prompt):
set GITHUB_TOKEN=ghp_your_token_here
- On Linux/macOS:
export GITHUB_TOKEN=ghp_your_token_here
- Token must have
repo
,delete_repo
, andadmin:repo_hook
permissions.
- On Windows (Command Prompt):
-
(Optional) Edit the preserve list:
- Add repository names or regex patterns (one per line) to
config/preserve-projects.txt
to prevent changes.
- Add repository names or regex patterns (one per line) to
Archiving a repository makes it read-only and hides it from active development, but you can always unarchive it later.
Making a repository private hides it from the public, but you retain full control.
Deleting a repository is irreversible—all code, issues, and PRs are lost forever.
python main.py --cleanup
- Lists your repositories.
- For each repo, shows details and asks if you want to archive, make private, or skip.
- Skipped repos can be added to the preserve list.
- Type
q
at any prompt to abort.
To force archiving only:
python main.py --archive --cleanup
To make repositories private:
python main.py --private --cleanup
python main.py --export repos.csv
- Exports your repository metadata to a CSV file.
Recommended workflow:
-
Export all deletable repos:
python main.py --export repos.csv
-
Edit
repos.csv
to keep only the rows you want to process. -
Run batch operation:
Archive:
python main.py --batch-archive repos.csv
Make Private:
python main.py --batch-private repos.csv
Delete (dangerous!):
python main.py --batch-delete repos.csv
- You will be asked for confirmation before any batch operation starts.
python main.py --repos https://github.com/your-username/repo1 ^test-.*
- Archives (default) all matching repositories.
- You can specify full GitHub URLs and/or regex patterns.
To make private:
python main.py --private --repos https://github.com/your-username/repo1 ^test-.*
To delete instead of archive (dangerous!):
python main.py --delete --repos https://github.com/your-username/repo1 ^test-.*
- Archiving preserves your code and history, but prevents changes.
- Making private hides your repo from the public, but you keep full access.
- Deleting is permanent and cannot be undone.
Always archive or make private unless you are absolutely sure you want to delete.
-
Preserve List:
config/preserve-projects.txt
Add repo names or regex patterns (one per line) to exclude from any operation. -
Logging:
All actions are logged tologs/cleanup.log
with timestamps.
- Never store your token in a file.
- Token is read from the
GITHUB_TOKEN
environment variable only. - No sensitive information is logged.
- Python 3.7+
requests
🧹 Found 42 repositories for your-username at https://github.com/your-username.
Preserved patterns: 3
📦 https://github.com/your-username/my-repo (Public)
⭐ Stars: 5 | 🍴 Forks: 2
📝 Description: My awesome project
📄 README preview:
-------------------
# My Repo
...
-------------------
❓ What do you want to do with 'https://github.com/your-username/my-repo'?
[a] Archive [p] Make Private [d] Delete [s] Skip [q] Quit
MIT