Nâng CaoGit iconGit

CODEOWNERS file hoạt động như thế nào? Cách dùng để enforce review chính xác trong team lớn?

CODEOWNERS (/.github/CODEOWNERS) định nghĩa ai là owner của file/directory — GitHub tự động add họ làm required reviewers khi PR chạm vào files đó.

Format:

# Syntax: pattern  @user-or-team
*                   @default-reviewer          # catch-all
/src/auth/          @security-team             # auth code
/src/payments/      @payments-team @cto        # payments: 2 owners
*.sql               @dba-team                  # all SQL files
/docs/              @tech-writer               # documentation
/.github/           @devops-team               # CI/CD configs
/package.json       @lead-dev                  # dependency changes

Rules:
- Patterns match như .gitignore — last matching rule wins
- Cần enable "Require review from Code Owners" trong branch protection
- Team owners: @org/team-name (không phải individual)

Pitfalls:
- Quá nhiều owners → bottleneck (mọi PR cần 5 người approve)
- Không review CODEOWNERS định kỳ → departed employees vẫn là required reviewers
- Forgetting catch-all * rule → new files có thể không có owner

Best practice: ít owners per path, dùng teams thay vì individuals, review CODEOWNERS mỗi quarter.

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

Mở danh sách Git