You meant to put a one-line change on a working branch. Your editor or coding assistant sent it straight to the branch your team releases from. A GitHub branch rule can block that shortcut and give you a place to inspect the change before it lands. Start by finding the branch you actually need to protect.
Which branch should you protect?
Find the repository and branch that feed the release you care about. A branch is a named line of changes, and the default branch you see on GitHub might be different from the one your host uses. If your app deploys from Git, check the production branch in the host’s settings. For example, a Vercel project can use a branch other than main for production. If your team releases through a separate workflow, check what that workflow actually deploys.
Then write down one outcome. For example, “Changes to release should go through a pull request with the booking tests passing.” A branch rule governs changes to the branch. You still need to check which build your host serves and what happens in the live app.
What does each branch protection rule block?
A pull request is a proposal to bring changes from one branch into another. Requiring a pull request, requiring a check and requiring a review answer different questions.
| Requirement | What GitHub checks | What you still need |
|---|---|---|
| Require a pull request | An ordinary contributor without an exception must take the pull request route into the matching branch. | Read the proposed changes and verify the destination branch. |
| Require a named status check | GitHub waits for an acceptable result from the selected check. A failing or missing required result can block the update. | Choose a check that runs on the intended pull request and tests something that matters. |
| Require an approving review | GitHub waits for the configured number of approvals from eligible reviewers. | Make sure someone other than the author has the right access and time to review. |
For a first rule, choose the pull request route and one check the team already trusts, such as the check that exercises the booking flow. Add required approvals when another eligible person can do them. A classic protection rule also blocks force pushes, which can rewrite branch history, and branch deletion by default. Those settings can be changed separately.
How can you tell which rules apply to the branch?
Use the exact branch name for your first rule. release and release/next are different branch names. On a pull request, look at the base branch, the destination that will receive the change when you merge. A rule for the branch you are editing can be different from the rules for its destination.
GitHub has two places to set these requirements. One classic branch protection rule applies to a branch at a time. More than one active branch ruleset can apply, and those rulesets also layer with the applicable classic rule. If two active rules set different approval counts for the same branch, the stricter requirement applies. Check the existing rules before adding another one. Otherwise a rule you leave in place can still block a change you expected to pass.
Who can still change the branch without the normal checks?
Classic rules ordinarily exempt repository administrators and custom roles with branch-protection bypass permission. On a classic rule, Do not allow bypassing the above settings applies its restrictions to those roles as well. Check any separately configured pull request exceptions. For an active ruleset, inspect its bypass list for roles, teams and apps. A ruleset exception can be limited to the pull request route. Check the rules that apply to the intended person and branch.
The classic setting Restrict who can push to matching branches is available in public repositories owned by a GitHub Free organization and in organization repositories on GitHub Team or Enterprise Cloud. It limits which people, teams or apps can push. This list alone does not block repository administrators or apps with admin permissions. Check separately which pull request and status check requirements apply to each of them.
When does an approval count?
An approval must come from someone other than the author who meets the rule’s requirements. For classic required reviews, use a reviewer with write access, and check whether the rule also asks for a code owner. Have the reviewer open Files changed and check the proposed result before submitting Approve as their review.
A CODEOWNERS file says who looks after particular files. GitHub reads it from the pull request’s destination branch and requests a review when a ready pull request changes a matching file. A required code owner approval is a separate setting. Code owners need write access. If you name a team, the team itself must be visible and have write access even if its members already have it individually.
An organization can also set a ruleset to require approvals from a specific team when selected files change. Check the file paths and give the team itself write access. This team rule is available for organization-owned repositories.
Where do you set up GitHub branch protection?
First check who owns the repository and whether GitHub labels it Public or Private. For a repository owned by an organization, check that organization’s plan. On GitHub.com, classic protections and branch rulesets are available for public repositories on Free and for private repositories on eligible plans such as Pro for a personal repository or Team and Enterprise Cloud for an organization. You need repository admin access or an assigned role that can edit repository rules. If the private repository is on Free, check what GitHub Free includes for a private repository before looking for a setting.
- Open Settings in the intended repository. Choose Branches to add a classic protection rule. For a ruleset, open Rulesets in the sidebar, then choose New ruleset → New branch ruleset.
- Target the exact branch and choose the pull request and check requirements. Select the exact check name shown on a real pull request in that repository. Add an approval requirement only when an eligible reviewer can meet it.
- For a ruleset, confirm it is Active if you expect it to enforce the rule. Check any rules that already match the branch and record who has an exception before you depend on it.
What works if you are the only person making changes?
Use a working branch and pull request so you can inspect your own changes before merging. If your repository plan supports enforcement, a required pull request and a real check can still help. Leave required approvals off if you have no eligible second reviewer.
If your private plan does not support branch enforcement, keep the repository private and use the review route as a team habit. You can still open a pull request, look at the files and check the result before merging. A habit is useful, and an ordinary direct push remains possible without an enforcing rule.
How do you check that the rule blocks the right thing?
Use a paper example or a separate private practice repository you are allowed to use. For a repository test, confirm the plan supports the rule, check that your local copy points to the practice repository and make sure it has no production connection, real data or secrets. Start with a dummy release-note.txt on practice-release. Create a working branch from that target, make a one-line change and commit it on your working branch. Require a pull request and a sandbox check that actually runs for that target. Use a test contributor who can normally write to the practice repository and has no bypass permission.
| Try this with the dummy change | What you should see |
|---|---|
Make a normal direct push aimed at practice-release without a pull request. | Look for a rejection that names the pull request requirement, and check that the target still has the old note. A missing check, permission error or wrong branch can also reject a push. Confirm which rule blocked it before marking the test as passed. |
Push the working branch to the same practice repository. Open a pull request from it into practice-release and inspect the merge box before the required check or approval is ready. | GitHub identifies what is missing. If the check fails, fix the dummy change and wait for the check on the new version. |
| Review the same pull request, confirm that the named check actually ran and passed, and get the required approval if you enabled it. | An eligible contributor can merge once the remaining conditions are met. In the sandbox, reopen release-note.txt on the target branch and confirm the expected line is there. |
If you lack a suitable sandbox, a named check or an authorized test contributor, walk through the table on paper. Record the expected results and leave enforcement unverified until you can observe both paths in an isolated repository.
What should the team do when a merge is blocked?
Read the pull request’s merge box first. If the named check is missing, verify the target branch, the exact check name and whether its workflow runs for this pull request. Give required jobs distinct names. A workflow that never runs can leave a requirement pending. A skipped job can count as satisfied, so open the check result and verify the work you expected actually ran. If the check ran and failed, fix the change and wait for a result on the new version. If an approval is missing, ask an eligible reviewer to check that version.
Write down who handles an urgent fix when the usual route cannot meet the deadline. If a team authorizes an exception, record the person or role, the branch, the reason, the checks still required and when to remove it. Use the normal reviewed pull request for urgent work whenever that route is available.
What should you keep after the rehearsal?
Keep a short record beside the project with the protected branch, the reason it matters, the named checks and the expected paths for ordinary contributors and any approved exception. Save the two sandbox outcomes and assign someone to revisit them when the release branch, check name or reviewer access changes.