Python scripts for managing GitHub repositories and branch protection using the GitHub REST API.
Lists all repositories in a GitHub organization and exports them to private.list and public.list.
python list_repos.py <organization_name>Protects main branches of repositories listed in a file with pull request requirements.
python protect_branches.py <repo_list_file>- Install dependencies:
pip install -r requirements.txt - Set GitHub token:
- Environment:
export GITHUB_TOKEN=your_token - File:
echo "your_token" > github-token.txt
- Environment:
- Requires pull requests for main branch
- Code owner reviews required (if CODEOWNERS exists)
- Repository owners can bypass restrictions
- No minimum approval count
- Allows force pushes and deletions
# List all repos in organization
python list_repos.py nexomis
# Protect repositories from a list
python protect_branches.py test.list
python protect_branches.py private.listRepository list files contain one repo per line:
owner/repo1
owner/repo2
- Python 3.6+
- GitHub token with
reposcope - Admin access for branch protection