Skip to content

Say hello to the new PR page.

Read more

Setting rules and policies for GitHub pull requests

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Pull requests (PRs) are the primary means through which changes are reviewed and integrated into larger codebases on GitHub. This guide explores how to establish robust PR rules and policies on GitHub.

The establishment of pull request policies helps maintain code quality and ensures that changes meet organizational standards before merging. Here are the steps to set up basic GitHub PR rules with branch protection rules

  1. Navigate to your repository settings on GitHub and select "Branches" in the sidebar.

screenshot of branch settings

  1. Branch protection rules: Click on "Add rule" to define policies for your target branch (commonly main). Here you can:
    • Require pull requests before merging, ensuring all changes are reviewed.
    • Require status checks to pass before merging, such as continuous integration (CI) builds.
    • Enforce a minimum number of reviewer approvals.
    • Restrict who can push to the protected branch, often reserved for maintainers or automated systems like CI.

screenshot of adding a rule

  1. CODEOWNERS file: Create a CODEOWNERS file at the root of your repository to automatically assign reviewers to PRs based on the files changed. This ensures that the right subject matter experts review relevant changes.

Suppose you want to enforce a rule where all changes to the main branch require at least two approvals and passing CI tests. Your branch protection rule settings might look like this:

  • Require a pull request before merging.
  • Require status checks to pass before merging.
  • Require at least 2 approvals.
Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Built for the world's fastest engineering teams, now available for everyone