A Windows batch script that allows you to add collaborators to multiple GitHub repositories in bulk using the GitHub CLI. Perfect for repository maintainers, team leads, and organizations who need to efficiently grant access to new team members across multiple projects.
- Bulk Operations: Add one collaborator to multiple repositories with a single command
- Flexible Permissions: Support for all GitHub permission levels (read, write, admin, maintain, triage)
- Smart Validation: Built-in checks for GitHub CLI installation, authentication, and user existence
- Detailed Reporting: Progress indicators and comprehensive success/failure summaries
- Error Handling: Robust error detection with specific troubleshooting guidance
- Organization Support: Works with both personal and organization repositories
- Safe Operation: Confirmation prompts and validation before making changes
Before using this script, ensure you have:
-
GitHub CLI installed: Download from GitHub CLI or install via:
winget install --id GitHub.cli
-
GitHub Authentication: Authenticate with GitHub CLI using one of these methods:
Method 1: Web Browser Authentication (Recommended)
gh auth login --web
This will open your browser and guide you through GitHub's OAuth flow.
Method 2: Personal Access Token
gh auth login --with-token
Then paste your personal access token when prompted. To create a token:
- Go to GitHub Settings > Personal Access Tokens
- Click "Generate new token (classic)"
- Select scopes:
repo,admin:org,user - Copy the generated token and paste it in the terminal
-
Admin Access: You must have admin permissions on the repositories you want to modify
-
Windows Environment: This is a Windows batch script (
.batfile)
Edit these three variables at the top of the script:
set COLLABORATOR_USERNAME=usernameReplace username with the actual GitHub username (not email address) of the person you want to add.
set PERMISSION=writeChoose from these permission levels:
read: Can view and clone repositorieswrite: Can view, clone, and push to repositoriesadmin: Full access including settings and collaborator managementmaintain: Can manage some repository settings but not sensitive onestriage: Can manage issues and pull requests but not push code
set REPOS=repo1 repo2 repo3Replace with your actual repository names, separated by spaces. Example:
set REPOS=my-website my-api-project documentation-siteIf you've never used GitHub CLI before, follow these steps:
-
Install GitHub CLI (if not already installed):
winget install --id GitHub.cli
-
Open a new terminal window (Command Prompt or PowerShell)
-
Authenticate with GitHub:
gh auth login --web
- This will display a code and open your browser
- Authorize the GitHub CLI application
- Return to terminal when prompted
-
Verify authentication:
gh auth status
You should see your username and "Logged in to github.com"
- Download the script: Save the batch file to your computer
- Configure: Edit the three configuration variables as described above
- Run: Execute the script from Command Prompt or PowerShell
- Follow prompts: The script will guide you through the process
# Navigate to script location
cd C:\path\to\script
# Run the script
add_github_collaborator.batThe script provides detailed output including:
====================================
GitHub Bulk Collaborator Management
====================================
Configuration:
- Collaborator: johndoe
- Permission: write
- Repositories: website api docs
β
GitHub CLI is installed and available
β
GitHub authentication verified
β
Current GitHub user: myusername
β
GitHub user 'johndoe' exists
Ready to add johndoe as collaborator with 'write' permissions
to repositories owned by myusername
[1] Processing repository: website
β
SUCCESS: Added johndoe to 'website'
[2] Processing repository: api
β
SUCCESS: Added johndoe to 'api'
[3] Processing repository: docs
β FAILED: Repository 'docs' does not exist or is not accessible
====================================
OPERATION SUMMARY
====================================
Total repositories processed: 3
Successful additions: 2
Failed additions: 1
-
Issue: "You are not authenticated with GitHub"
-
Solutions:
Option 1: Web Authentication (Easiest)
gh auth login --web
- This opens your browser automatically
- Click "Authorize github" when prompted
- Follow the on-screen instructions
- Return to terminal once complete
Option 2: Device Code Authentication
gh auth login
- Select "GitHub.com"
- Choose "HTTPS" for Git operations
- Choose "Login with a web browser"
- Copy the provided code and open the URL
- Paste the code in your browser
Option 3: Personal Access Token
gh auth login --with-token
- Create a token at GitHub Settings
- Required scopes:
repo,admin:org,user - Paste the token when prompted in terminal
Verify Authentication:
gh auth status
This should show your logged-in status and available scopes.
- Issue: "Repository does not exist or is not accessible"
- Solutions:
- Verify repository name spelling
- Ensure you have admin access to the repository
- Check if repository is under your personal account vs an organization
- Issue: "Could not add collaborator"
- Solutions:
- Verify you have admin rights to the repository
- Check organization policies that might restrict collaborator additions
- Ensure the repository allows external collaborators
- Issue: "GitHub CLI is not installed"
- Solutions:
- Install via
winget install --id GitHub.cli - Download from GitHub CLI releases
- Add GitHub CLI to your system PATH
- Install via
- The script only adds collaborators; it doesn't remove or modify existing ones
- All operations are logged with detailed output for audit purposes
- The script validates usernames before attempting to add them
- Requires explicit confirmation before making changes
- Uses GitHub's official API through the GitHub CLI
For repositories that fail automation, you can manually add collaborators via:
- Navigate to
https://github.com/USERNAME/REPOSITORY/settings/access - Click "Add people"
- Enter the collaborator's username
- Select the appropriate permission level
- Click "Add USERNAME to this repository"
Feel free to suggest improvements or report issues. This script is designed to be simple, safe, and effective for bulk collaborator management.
MIT License - Feel free to use, modify, and distribute as needed.
Note: This script is designed for Windows environments. For macOS/Linux users, consider adapting the logic to a shell script format.