Data report"State of code review 2024" is now liveRead the full report

Mandatory pull request checks and requirements in GitHub

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


In collaborative software development environments, maintaining code quality and consistency is important. GitHub provides several tools to help enforce quality standards, including the ability to require specific checks on pull requests before they can be merged. This guide explains how to set up and manage mandatory pull request checks in GitHub, ensuring that all contributions meet your project’s standards.

Pull request checks are automated tests or processes that run every time a new commit is pushed to a pull request. These can include tests for syntax errors, build failures, and automated code reviews. These checks ensure that the new changes meet the predetermined criteria set by the project maintainers before being integrated into the main branch.

To improve the stability and integrity of your project, you can configure GitHub to require certain status checks to pass before a pull request can be merged. Here’s how you can set up these requirements:

  1. Navigate to your repository settings:

    • Go to your GitHub repository, click on 'Settings', and then select 'Branches' from the sidebar.
  2. Add branch protection rules:

    • In the 'Branch protection rules' section, click on 'Add rule'.
    • Specify the branch name pattern this rule will apply to, typically main or master.
  3. Enable required status checks:

    • Scroll to 'Require status checks to pass before merging' and check the box.
    • You can now select the checks that you want to require. GitHub populates this list based on the checks previously run on your repository.
  4. Configure additional rules:

    • Require branches to be up to date before merging: Ensures the pull request branch has been updated with the latest base branch changes, which can help prevent merge conflicts.
    • Include administrators: Apply the same rules to administrators to ensure no one bypasses the checks.
  5. Save the changes:

    • Click 'Save changes' to enforce these rules on the specified branches.

A common practice is to use Continuous Integration (CI) pipelines as required status checks. These pipelines can build the project, run tests, and perform static code analysis.

  1. Set up a CI workflow using GitHub Actions:

    • Create a .github/workflows/ci.yml file in your repository.
    • Define steps like installing dependencies, building your project, and running tests.
  2. Configure the CI workflow as a required check:

    • Once you push the workflow file and run it for the first time, it will appear in the list of available status checks in the branch protection settings.
    • Go back to your branch protection settings and select this new CI workflow as a required status check.
  • Use a tool like Graphite Protections: Go a step further than the checks that GitHub provides and implement fine-grained control over PR mergeability based on file path, language, team, and more.
  • Automate as much as possible: The more checks you can automate, the less manual review is required, reducing the potential for human error.
  • Keep your checks fast and relevant: Optimize your CI jobs to run quickly and avoid unnecessary steps that can delay the merging process.
  • Communicate requirements clearly: Ensure that all contributors know what checks are in place and what is required for a pull request to be merged. This can be documented in a CONTRIBUTING.md file in your repository.

Implementing mandatory pull request checks in GitHub helps ensure that all contributions adhere to your project's quality standards, leading to a more stable and reliable software development lifecycle. This practice not only catches errors early but also enforces a discipline of quality among all contributors.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2