Skip to content

Say hello to the new PR page.

Read more

Prevent merge without review in GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer
Try Graphite

Ensuring that all changes are properly reviewed before they are merged into the main branch is important for maintaining code quality. GitHub provides several tools to help enforce branch policies, including settings to block merging of pull requests without required reviews. This guide details how to configure your GitHub repository to prevent merges without a review, enhancing your project's integrity and collaboration.

Pull request reviews are critical for:

  • Catching bugs
  • Ensuring code consistency
  • Facilitating context sharing among team members
  • Enhancing code quality through peer feedback

Start by going to your GitHub repository page. Click on "Settings" near the top right of the page, then on the left sidebar, click on "Branches" under the "Code and automation" section.

In the "Branches" section, you’ll find the "Branch protection rules" area. Click on "Add rule" to create a new branch protection rule.

Specify the branch name in the "Branch name pattern" field. Typically, this would be main or whichever other branch you are using as your mainline where merges should be controlled.

Under "Protect matching branches," find and check the option "Require pull request reviews before merging." This setting does the following:

  • Disables direct commits to the protected branches.
  • Requires that all pull requests must be reviewed and approved before merging.

For additional control, you might consider these options:

  • Require review from Code Owners: If you use a CODEOWNERS file, you can enforce that only code owners can approve changes to certain parts of the code.
  • Dismiss stale pull request approvals when new commits are pushed: This ensures that approvals are only valid for the current state of the pull request, requiring re-review if further changes are made after approval.

To fully ensure that no merges occur without review, check the following options under the same settings:

  • Don't allow merging with unresolved conversations: Prevents merging until all comment threads are resolved.
  • Include administrators: Applies the same rules to administrators to ensure that no one can bypass the review requirements.

After configuring the settings, click on "Save changes" at the bottom of the page to enforce the new branch protection rules.

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