跳至主要内容

GitHub Repository Settings Guide

This guide covers recommended GitHub repository settings for projects using this template.

Branch Protection Rules

Branch protection rules help maintain code quality and prevent accidental changes to important branches.

Navigate to SettingsBranchesAdd branch protection rule

SettingRecommendedWhy
Branch name patternmainProtects the default branch
Require a pull request before merging✅ YesEnsures code review
Require approvals1+At least one reviewer
Dismiss stale pull request approvals✅ YesRe-review after changes
Require review from Code OwnersOptionalIf using CODEOWNERS
Require status checks to pass✅ YesPrevents broken merges
Require branches to be up to date✅ YesAvoids merge conflicts
Require conversation resolution✅ YesAddress all feedback
Require signed commitsOptionalFor high-security projects
Include administrators✅ YesNo bypass for anyone
Allow force pushes❌ NoPreserve history
Allow deletions❌ NoProtect the branch

Required Status Checks

Based on this template's CI workflows, require these checks:

✅ lint (Lint)
✅ docs (Build Docs)
✅ links (Check Links) - optional
✅ analyze (CodeQL) - optional

How to Configure

  1. Go to your repository on GitHub
  2. Click SettingsBranches
  3. Under "Branch protection rules", click Add rule
  4. Enter main as the branch name pattern
  5. Enable the recommended settings above
  6. Click Create or Save changes

Security Settings

Navigate to SettingsCode security and analysis

FeatureRecommendedPurpose
Dependency graph✅ EnableVisualize dependencies
Dependabot alerts✅ EnableSecurity vulnerability alerts
Dependabot security updates✅ EnableAuto-fix security issues
Dependabot version updates✅ EnableKeep dependencies current
Code scanning✅ EnableCodeQL security analysis
Secret scanning✅ EnableDetect leaked secrets
Push protection✅ EnableBlock secret commits

Repository Features

Navigate to SettingsGeneralFeatures

FeatureRecommendedPurpose
Wikis❌ DisableUse docs/ instead
Issues✅ EnableBug reports and features
SponsorshipsOptionalAccept funding
Preserve this repositoryOptionalArctic Code Vault
Discussions✅ EnableCommunity Q&A
ProjectsOptionalProject management

Pull Request Settings

Navigate to SettingsGeneralPull Requests

SettingRecommendedWhy
Allow merge commits✅ YesStandard merges
Allow squash merging✅ YesClean history option
Allow rebase mergingOptionalLinear history
Always suggest updating pull request branches✅ YesKeep PRs current
Allow auto-merge✅ YesMerge when checks pass
Automatically delete head branches✅ YesClean up after merge

Actions Settings

Navigate to SettingsActionsGeneral

Actions Permissions

  • Allow all actions and reusable workflows (recommended for most projects)
  • Or limit to specific actions for higher security

Workflow Permissions

SettingRecommended
Read repository contents and packages permissionsDefault
Allow GitHub Actions to create and approve pull requests✅ Enable (for Dependabot)

Environment Protection Rules

For deployment workflows, create protected environments:

  1. Go to SettingsEnvironments
  2. Click New environment
  3. Name it (e.g., production, github-pages)
  4. Configure protection rules:
    • Required reviewers: Add approvers for deployments
    • Wait timer: Optional delay before deployment
    • Deployment branches: Limit which branches can deploy

Webhooks and Integrations

Common useful integrations:

IntegrationPurpose
Slack/DiscordNotifications
CodeClimateCode quality
CodecovTest coverage
SnykSecurity scanning

Access Management

Collaborator Roles

RolePermissions
ReadView code, open issues
TriageManage issues and PRs
WritePush code, merge PRs
MaintainManage repo (no settings)
AdminFull access

Team Recommendations

For organizations:

  • Create a maintainers team with Admin access
  • Create a contributors team with Write access
  • Use CODEOWNERS for automatic review assignment

Checklist

Use this checklist when setting up a new repository:

  • Enable branch protection on main
  • Require at least 1 PR approval
  • Enable required status checks
  • Enable Dependabot alerts and updates
  • Enable secret scanning with push protection
  • Enable Discussions for community
  • Configure auto-delete for merged branches
  • Set up CODEOWNERS file
  • Create protected environment for deployments