Restricting Merges with Policies, Protection Rules and Rulesets
This lesson explains how to control how changes enter a branch and who may bypass those controls.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how required policies block direct pushes.
- Identify bypass permissions.
- Explain the purpose of a merge queue.
- Distinguish rulesets from branch protection rules.
Restricting merges in Azure Repos
As soon as a required branch policy is set on a branch, direct pushes to that branch are blocked, and all changes must arrive through a pull request. This is an important side effect, because a separate setting is not needed. Policies set as optional only give advice, and they do not block completion.
The Limit merge types policy allows selected options among basic merge, squash, rebase and fast-forward, and rebase with merge commit. A team that wants linear history allows squash, or rebase and fast-forward, and disables basic merge.
Bypass permissions
Two repository permissions allow bypassing, and they must be tightly limited: Bypass policies when completing pull requests and Bypass policies when pushing. These replace the older blanket exemption. Since a person with these rights can avoid all controls, an audit of who holds them is a sound practice. Project Collection Administrators can grant themselves such permissions, so administrator group membership is also part of this control. Bypass actions are recorded in audit logs.
Merge restrictions in Azure Repos
Restricting merges in GitHub
A GitHub branch protection rule can restrict who may push to matching branches, allow or block force pushes and deletions, and require linear history. Require linear history rejects merge commits, so pull requests must be squashed or rebased.
Do not allow bypassing the above settings applies the rule to administrators as well. Without this option, a repository administrator can merge without meeting the requirements, which many compliance programmes do not accept.
Merge queue
When many pull requests merge into a busy branch, two changes can each pass checks independently, and yet break main when combined. A merge queue takes approved pull requests in order, tests each one against the result of those ahead of it, and merges only if the tests pass. A workflow must listen to the merge_group event for the required checks to run in the queue.
Branch protection and the merge queue
Repository rulesets
Rulesets are the newer GitHub mechanism, and they do more than branch protection rules. A ruleset is a named list of rules that targets branches or tags by pattern. Rulesets are available according to plan, and they can be defined at repository or organization level, so that one policy can govern many repositories.
The behavioural differences are worth knowing. Several rulesets can apply to the same branch at once, and the most restrictive version of a rule wins, whereas only one branch protection rule applies to a branch. A ruleset's enforcement status can be changed without deleting it. Anyone with read access can view active rulesets, which makes the rules transparent. Bypass can be granted to specific roles, teams or GitHub Apps. Rulesets can also control commit metadata, such as message patterns. They layer with branch protection rules, so both can apply together.
The following diagram shows one GitHub organization ruleset and the 200 repositories it covers.

Branch protection rule or ruleset?
Closing a bypass
An organization has 200 GitHub repositories on Enterprise Cloud. Compliance requires that every default branch requires a pull request with one approval and that no administrator can bypass this. New repositories must be covered automatically. What should you implement?
You should create an organization-level ruleset targeting the default branch of all repositories, with a pull request rule requiring one approval, and an empty bypass list. An organization ruleset covers new repositories without further work. Branch protection rules would need to be created in each repository, and a nightly script applying them would leave gaps. Reviewing administrator actions afterwards would detect a bypass but would not prevent it.
Why does a merge queue need the merge_group event?
Show answer
The queue tests each change against those ahead of it, so required workflows must run on that event for the checks to report.
Exam Tips
Remember for the exam
- A required branch policy blocks direct pushes.
- Bypass permissions in Azure Repos should be tightly limited and audited.
- Require linear history rejects merge commits.
- Organization rulesets cover new repositories automatically.
- A merge queue needs workflows that run on the merge_group event.