A robust, modular command-line tool for managing GitHub repositories through the GitHub API. Built with safety, reliability, and ease of use in mind.
- π List repositories (all, public, private, or archived)
- π Get detailed repository information
- π Change repository visibility (public/private) with safety checks
- π€ Support for both authenticated user and specific user repositories
- π Pagination support for large repository lists
- π§ͺ Dry-run mode - Preview changes before applying them
- β Confirmation prompts - Prevent accidental bulk operations
- π‘οΈ Input validation - Comprehensive validation of all inputs
- π Ownership verification - Ensures you own repositories before modifying them
- β‘ Rate limit management - Intelligent API rate limiting
- π¨ Enhanced error handling - Clear, actionable error messages
- π¦ Modular architecture - Clean, maintainable codebase
- π§ Multiple configuration options - Environment variables, config files
- π Progress tracking - See success/failure counts for bulk operations
- π Debug mode - Raw API access for troubleshooting
bash(4.0 or later)jqfor JSON processingcurlfor API requestsgdate(GNU date) for timestamp handling- GitHub Personal Access Token with appropriate permissions
-
Clone the repository:
git clone https://github.com/yourusername/gh-control.git cd gh-control -
Make the script executable:
chmod +x gh-control.sh
-
Set up authentication (choose one method):
Method 1: Environment Variable (Recommended)
export GH_ACCESS_TOKEN="your_token_here"
Method 2: Configuration File
cp config.example .env # Edit .env and add your tokenMethod 3: Legacy Token File
echo 'GH_ACCESS_TOKEN="your_token_here"' > .github_token chmod 600 .github_token
# Test the installation
./gh-control.sh help
# Try a safe command
./gh-control.sh get-repos --user octocat# Show help (no authentication required)
./gh-control.sh help
# List all repositories for a user
./gh-control.sh get-repos --user octocat
# List your private repositories
./gh-control.sh get-private-repos --auth-user
# Get details of a specific repository
./gh-control.sh get-repo octocat/Hello-World# Preview changes before applying (dry-run mode)
DRY_RUN=true ./gh-control.sh make-repos-private repo1 repo2
# Skip confirmation prompts (for automation)
FORCE=true ./gh-control.sh make-repos-public repo1 repo2
# Combine both for testing automation scripts
DRY_RUN=true FORCE=true ./gh-control.sh make-repos-private repo1 repo2# Make repositories private (with confirmation)
./gh-control.sh make-repos-private repo1 repo2
# Make repositories public (with confirmation)
./gh-control.sh make-repos-public repo1 repo2| Command | Description | Authentication Required |
|---|---|---|
help |
Show help message and exit | β No |
get {PATH|URL} |
Make HTTP GET request to API endpoint (debug) | β Yes |
get-repo OWNER/REPO |
Get details of a specific repository | β Yes |
| Command | Description | Options |
|---|---|---|
get-repos |
List all repositories | --user USER or --auth-user |
get-public-repos |
List public repositories only | --user USER or --auth-user |
get-private-repos |
List private repositories only | --user USER or --auth-user |
get-archived-repos |
List archived repositories only | --user USER or --auth-user |
| Command | Description | Safety Features |
|---|---|---|
make-repos-private REPO... |
Make repositories private | β Ownership check, confirmation prompt |
make-repos-public REPO... |
Make repositories public | β Ownership check, confirmation prompt |
--user USER- List repositories for specified user--auth-user- List repositories for authenticated user
DRY_RUN=true- Show what would be done without making changesFORCE=true- Skip confirmation prompts for destructive operationsKEEP_TMP=y- Preserve temporary files for debugging
The tool requires a GitHub Personal Access Token with the following permissions:
| Permission | Required For | Description |
|---|---|---|
repo |
Repository management | Full control of private repositories |
read:org |
Organization repos | Read organization data (if accessing org repositories) |
- Create a token at GitHub Settings > Developer settings > Personal access tokens
- Select scopes based on your needs (see table above)
- Configure the tool using one of the authentication methods above
The tool is built with a modular architecture for maintainability and extensibility:
gh-control/
βββ gh-control.sh # Main script and command dispatcher
βββ lib/ # Modular library components
β βββ logging.sh # Logging utilities
β βββ config.sh # Configuration management
β βββ validation.sh # Input validation functions
β βββ github-api.sh # GitHub API interactions
β βββ safety.sh # Safety features (dry-run, confirmations)
β βββ commands.sh # Command implementations
βββ config.example # Example configuration file
βββ README.md # This file
- β Never commit your GitHub token to version control
- π Use environment variables for production deployments
- π Secure file permissions (
chmod 600) for token files - π Rotate tokens regularly and revoke unused ones
- π― Use minimum required permissions for your token
- π§ͺ Always test with dry-run before bulk operations
- β Review confirmation prompts carefully
- π€ Verify repository ownership before making changes
- π Monitor API rate limits to avoid service disruption
"Failed to parse API response status"
- Usually indicates network connectivity issues
- Check your internet connection and GitHub API status
"Authentication error: Bad credentials"
- Verify your GitHub token is correct and not expired
- Ensure the token has the required permissions
"Rate limit exceeded"
- Wait for the rate limit to reset (usually 1 hour)
- Consider using a token with higher rate limits
"Repository not found"
- Check the repository name spelling
- Verify you have access to the repository
- Ensure the repository exists
Enable debug information:
KEEP_TMP=y ./gh-control.sh your-command
# Check the temporary directory for API response detailsBuilt with βοΈ by @eronmiranda
A robust, safety-first approach to GitHub repository management.