Trung BìnhGit iconGit

Branch protection rules trên GitHub: cần cấu hình gì để prevent team push thẳng lên main?

Vào GitHub repo → Settings → Branches → Add branch protection rule cho main:

Tối thiểu cần bật:
- Require a pull request before merging — không ai push thẳng
- Require approvals (1-2 reviewers)
- Dismiss stale pull request approvals when new commits are pushed — re-review sau mỗi force push
- Require status checks to pass — CI phải xanh trước khi merge
- Require branches to be up to date before merging — không merge stale branch
- Include administrators — áp dụng cả cho repo owner

Nâng cao:
- Require signed commits — GPG/SSH signature bắt buộc
- Require linear history — chỉ cho phép squash/rebase merge (không merge commit)
- Restrict who can push to matching branches — chỉ CI bot được push sau review

Lưu ý: Include administrators hay bị bỏ quên — không bật thì owner vẫn có thể bypass. Với GitHub Enterprise: dùng ruleset thay vì branch protection — linh hoạt hơn, có thể apply cho pattern nhiều branches.

Xem toàn bộ Git cùng filter theo level & chủ đề con.

Mở danh sách Git