Automated scripts and documentation for applying GitHub repository best practices across personal and organization accounts.
This repository contains battle-tested scripts and comprehensive documentation for:
- β
Standardizing default branch to
mainacross all repositories - β Applying best practice settings (auto-delete branches, squash-only merges, etc.)
- β Creating new repositories with all best practices automatically applied
- β Bulk fixing existing repositories
- β Organization-wide configuration management
.
βββ scripts/
β βββ apply-repo-settings.sh # Apply best practices to a single repo
β βββ gh-repo-create-with-defaults.sh # Create new repo with all defaults
β βββ rename-to-main.sh # Bulk rename master β main
β βββ open-org-settings.sh # Open all org settings pages
βββ docs/
β βββ repository-settings.md # Complete settings guide with rationale
β βββ repo-defaults-setup.md # Setup guide for new repo defaults
β βββ bulk-fix-guide.md # Bulk operations guide
β βββ default-branch-setup.md # Default branch standardization
βββ README.md # This file
git clone https://github.com/YOUR-ORG/github-best-practices.git
cd github-best-practices# Apply to a specific repo
./scripts/apply-repo-settings.sh owner/repo-name
# Or from within a repo directory
cd ~/path/to/your/repo
../github-best-practices/scripts/apply-repo-settings.sh./scripts/gh-repo-create-with-defaults.sh my-new-repo --private./scripts/rename-to-main.sh| Setting | Value | Benefit |
|---|---|---|
| Default Branch | main |
Industry standard, inclusive naming |
| Auto-delete head branches | β | Keeps repo clean, reduces clutter |
| Allow auto-merge | β | Enables automated PR workflows |
| Allow squash merging | β (only option) | Clean, linear history |
| Require linear history | β | Prevents messy merge commits |
| Require conversation resolution | β | Ensures all feedback addressed |
| Wiki | β | Use README/docs instead |
| Projects | β | Use GitHub Projects at org level |
- β Require pull request before merging
- β Dismiss stale reviews when new commits pushed
- β Require conversation resolution before merging
- β Allow force pushes (for cleaner history)
- Repository Settings - Complete settings reference with before/after comparison
- Repo Defaults Setup - Configure defaults for future repositories
- Bulk Fix Guide - Apply settings to multiple repositories
- Default Branch Setup - Standardize to "main" across account and orgs
Apply all best practice settings to a single repository.
Usage:
./scripts/apply-repo-settings.sh [owner/repo]
Examples:
./scripts/apply-repo-settings.sh myorg/myrepo
cd ~/myrepo && ../scripts/apply-repo-settings.shWhat it does:
- Auto-delete head branches: enabled
- Auto-merge: enabled
- Squash merging: only option
- Linear history: required
- Conversation resolution: required
- Wiki & Projects: disabled
- Branch protection: configured
Create a new repository with all best practices automatically applied.
Usage:
./scripts/gh-repo-create-with-defaults.sh REPO_NAME [OPTIONS]
Examples:
./scripts/gh-repo-create-with-defaults.sh my-new-project --private
./scripts/gh-repo-create-with-defaults.sh my-org/new-service --publicWhat it does:
- Creates repo with "main" as default branch
- Applies all best practice settings
- Configures branch protection
- Ready to clone and use immediately
Bulk rename default branches from "master" to "main" across all repositories.
Usage:
./scripts/rename-to-main.sh
Interactive prompts:
- Confirms before proceeding
- Shows progress for each repo
- Reports success/failureWhat it does:
- Scans all non-archived, non-fork repos
- Identifies repos using "master"
- Renames branches using GitHub API
- Updates default branch setting
Open organization settings pages for manual configuration.
Usage:
./scripts/open-org-settings.shWhat it does:
- Fetches all organizations you belong to
- Opens repository defaults page for each org
- Provides instructions for manual configuration
# Verify git is configured for "main"
git config --global --get init.defaultBranch
# List repos still using "master"
gh repo list YOUR-USERNAME --limit 1000 --json name,defaultBranchRef | \
jq -r '.[] | select(.defaultBranchRef.name == "master") | .name'
# Check organization default branch settings
gh api user/orgs --jq '.[].login' | while read org; do
echo "$org: $(gh api orgs/$org --jq '.default_repository_branch')"
done
# Verify a specific repo's settings
gh repo view OWNER/REPO --json \
defaultBranchRef,deleteBranchOnMerge,hasWikiEnabled,hasProjectsEnabledThe tech community has moved from "master" to "main" to use more inclusive language and align with industry standards. GitHub uses "main" as default for all new accounts created after October 2020.
Prevents branch clutter and reduces confusion about which branches are active. After a PR is merged, the feature branch is no longer needed.
Creates a clean, linear history by combining all commits from a PR into a single commit. Makes it easier to:
- Understand project history
- Revert changes if needed
- Perform git bisect operations
Prevents merge commits, keeping the main branch history clean and easy to follow. Every commit represents a complete feature or fix.
Ensures all review comments are addressed before merging. Improves code quality and team communication.
Repository wikis and projects are often neglected and create duplicate sources of truth. Better alternatives:
- Use
docs/folder or README for documentation - Use GitHub Projects at organization level for project management
- Use Issues for task tracking
Edit scripts/apply-repo-settings.sh to adjust settings:
# Example: Enable wiki
gh api -X PATCH repos/$REPO \
-f has_wiki=trueSee the GitHub REST API documentation for all available settings:
From standardizing 61 repositories and 6 organizations:
Before:
- Mixed "master" and "main" branches (42 repos using "master")
- Inconsistent settings across repositories
- Manual configuration for each new repo
- Branch clutter from undeleted feature branches
After:
- 100% standardized on "main" (55 active repos)
- Consistent best practices across all repos
- Automated repo creation with defaults
- Clean repository state with auto-deletion
Time Saved:
- New repo setup: ~5 minutes β 30 seconds
- Bulk operations: Manual β Automated
- Branch cleanup: Manual β Automatic
This repository represents best practices for GitHub repository management. To contribute:
- Test changes in a personal fork first
- Document the rationale for any new practices
- Update relevant documentation in
docs/ - Ensure scripts are POSIX-compliant where possible
These scripts are provided as-is for use in managing GitHub repositories. Feel free to adapt them to your organization's needs.
Cause: Insufficient GitHub CLI permissions
Solution:
gh auth refresh -h github.com -s repo -s admin:orgCause: Empty repository or protected branch rules
Solution:
- Check if repo has any commits:
gh repo view OWNER/REPO - Verify branch protection isn't blocking:
gh api repos/OWNER/REPO/branches/main/protection
Cause: Need admin permissions
Solution: Contact org owner or verify permissions with:
gh api orgs/ORG-NAME/memberships/$(gh api user --jq .login)- GitHub Repository Best Practices
- GitHub CLI Documentation
- GitHub REST API Reference
- Inclusive Naming Initiative
Last Updated: June 2026
Maintained by: @restlessankyyy