A simple bash script to bulk archive and delete GitHub repositories using the GitHub CLI.
- List all your repositories with status (private/archived)
- Export repository list to a file
- Bulk archive repositories (private + archive OR public + archive)
- Bulk delete repositories
- Filter repositories (public only, non-archived only)
- Interactive menu interface
- Safety confirmations before destructive actions
- Automatic line number stripping from files
- File formatting utility to clean up repository lists
- Cross-platform support (Linux, macOS, Windows)
- GitHub CLI (
gh) - Installation Guide - Bash - Available on Linux, macOS, Git Bash (Windows), WSL
Windows:
winget install --id GitHub.climacOS:
brew install ghLinux (Debian/Ubuntu):
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install ghgh auth loginImportant: For repository deletion, refresh your authentication with the delete_repo scope:
gh auth refresh -h github.com -s delete_repo# Clone this repository
git clone https://github.com/yourusername/github-repo-bulk-manager.git
cd github-repo-bulk-manager
# Make the script executable
chmod +x manage-repos.sh./manage-repos.sh- List all repositories - View all repos with their status
- Export repository list to file - Save repo names to a text file
- Archive repositories (private + archive) - Make repos private AND archive them
- Archive repositories (keep public + archive) - Archive repos while keeping them public
- Delete repositories from file - Permanently delete repos
- Quick filter: Show only public repos - List public repositories
- Quick filter: Show only non-archived repos - List active repos
- Exit - Close the script
# 1. Run the script
./manage-repos.sh
# 2. Export repos to a file (option 2)
# Enter filename: repos-to-archive.txt
# 3. Edit the file to keep only repos you want to archive
nano repos-to-archive.txt # or use your preferred editor
# 4. Run the script again and select option 3
# Enter the filename when prompted
# 5. Confirm the action# 1. Export repos to a file
./manage-repos.sh
# Choose option 2
# 2. Edit the file to keep only repos you want to DELETE
nano repos-to-delete.txt
# 3. Run the script and select option 4
# You must type 'DELETE' to confirm
# 4. Repos will be permanently deletedThe script accepts repository names in the following formats:
username/repo-name
username/another-repo
It also automatically handles files with line numbers:
1→username/repo-name
2→username/another-repo
Comments and empty lines are ignored:
# This is a comment
username/repo-name
username/another-repo
# Another comment
If you want to clean up a file (remove line numbers, empty lines, comments):
# Make the format script executable
chmod +x format-repos-file.sh
# Clean up in place
./format-repos-file.sh repos.txt
# Or create a new clean file
./format-repos-file.sh repos.txt repos-clean.txtThis prevents having duplicate files like delete.txt and delete-clean.txt.
- Authentication check - Verifies GitHub CLI is authenticated before running
- Confirmation prompts - Asks for confirmation before destructive actions
- Delete protection - Requires typing "DELETE" to confirm deletion
- Progress feedback - Shows real-time status for each repository
- Error handling - Continues processing if individual repos fail
./manage-repos.sh
# Choose option 5 to list public repos
# Copy the output to a file
# Choose option 3 to archive them# Export all repos
./manage-repos.sh
# Choose option 2
# Edit the file and keep only test repos
grep -i "test" repos-list.txt > test-repos.txt
# Delete them
./manage-repos.sh
# Choose option 4 and enter test-repos.txt- Restart your terminal after installing GitHub CLI
- On Windows with Git Bash, you may need to add the path manually:
export PATH="$PATH:/c/Program Files/GitHub CLI"
- Ensure you have the
delete_reposcope:gh auth refresh -h github.com -s delete_repo
- Check if you have permission (owner/admin access required)
- Some organizations may restrict archiving
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - See LICENSE file for details
USE AT YOUR OWN RISK
- Repository deletion is permanent and cannot be undone
- Always review the list of repositories before confirming
- Consider backing up important repositories before deletion
- The author is not responsible for any data loss
Created by @anesask to simplify bulk repository management on GitHub.