GitHub Actions: Branch Protection and Required Checks
Branch protection is a rule that guards a branch. A required status check makes a red test block a merge.
The check that must pass
The job is named test. The branch rule picks it by that name.
jobs:
test:
runs-on: ubuntu-latestPick the check by name
This is the setting on the branch settings page.
# Branch settings: Require status checks to pass
# Required check: testA failing test blocks the merge
This test expects 6, but add(2, 3) gives 5. The run turns red.
test("add adds two numbers", () => {
assert.strictEqual(add(2, 3), 6);
});Example
name: CI
on:
push:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: '24'
- run: npm testKey points
- Branch protection: rules that guard a branch against direct pushes and bad merges.
- A required status check is a workflow job that must pass before a merge.
- Without branch protection, a red check is only a warning.
- With it switched on, a failing test blocks the merge button.
- The check is set on the branch settings page of the repo.
- The test job is picked by name as the required check.
- A pull request shows each check with a green tick or a red cross.
- The reader opens a pull request with a failing test and watches the merge stay blocked.
- Branch protection turns a red check from a warning into a stop sign.
In this example, the workflow runs on every push and every pull request. The job is named test, so the branch rule can pick it by name. Checkout downloads the code, setup-node installs Node 24, and npm test runs the tests. With branch protection switched on, this job must pass before the pull request can merge.
Note
Branch protection is a repo setting, not part of a workflow file.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What makes a failing test block a merge?