my-git

Branch Protection

English 中文

Branch protection is used to safeguard critical branches, preventing unreviewed, unverified, or high-risk operations from entering the mainline directly.

For team repositories, branches like main, master, and release/* should be managed as public assets.

Minimal Configuration

Small teams can start by enabling:

  1. Require pull request before merging
  2. Require status checks before merging
  3. Block force pushes
  4. Block deletions

This helps prevent the most common accidents first:

Configuration for Growing Teams

As the team grows, also enable:

These rules link review, CODEOWNERS, and CI into a complete merge workflow.

Common Pitfalls

1. Only protecting main

If the team uses release/* or hotfix/*, these branches should also be protected.

2. Adding rules but ignoring CI stability

Required checks must be stable. Flaky tests will cause the team to start bypassing rules.

3. Administrators bypassing rules long-term

Administrator bypasses should only be used in extremely rare emergency scenarios, and records should be kept.

Further Reading