Skip to Content
Native GitAdvancedBranch Protection

Branch Protection

Branch protection is a crucial feature used to safeguard your core or critical branches for security and quality control purposes. These rules help maintain code integrity by enforcing specific workflows and review processes.

Branch protection is available on the Enterprise plan.

Accessing Branch Protection Settings

To configure branch protection:

  1. Navigate to your API repository
  2. Select the Settings tab
  3. Go to Branches
  4. View existing rules under Branch Protection Rules or create new ones

Branch Settings page with the default branch and two protection rules

The same page sets the Default Branch of the repository.

Creating Protection Rules

Click the Add rule button to create a new branch protection rule. Each rule allows you to specify:

Branch Selection

  • Protected branch name pattern: Define which branches to protect using pattern-based branch names (e.g., main, release/*)
  • Apply rules to single branches or groups of branches using wildcards

File Protection

  • Protected file pattern: Files that cannot be changed directly, even by users who may otherwise change this branch
  • Unprotected file pattern: Files that users with write access can change directly, bypassing the push restriction

Separate several patterns with a semicolon (;).

Push

Choose one of:

  • Disable Push: No pushing is allowed to this branch
  • Enable Push: Anyone with write access can push to this branch, but not force push
  • Whitelist Restricted Push: Only the whitelisted users or teams can push to this branch, but not force push

Pull Request Approvals

  • Required approvals: The number of approvals needed before merging, from 0 to 10
  • Restrict approvals to whitelisted users or teams: Only reviews from Whitelisted reviewers and whitelisted teams count. Without this, reviews from anyone with write access count
  • Dismiss stale approvals: Old approvals are dismissed when new commits change the content of the pull request

Pull Request Merge

Choose who can merge:

  • Enable Merge: Anyone with write access can merge pull requests into this branch
  • Enable Merge Whitelist: Only the whitelisted users or teams can merge

And when a merge is blocked:

  • Block merge on rejected reviews: When an official reviewer requested changes, even with enough approvals
  • Block merge on official review requests: While official review requests are open, even with enough approvals
  • Block merge if pull request is outdated: While the pull request is behind its base branch

Team whitelists are available for organization repositories.

Add Branch Protection Rule dialog with the File Protection, Push and Pull Request Approvals sections

With properly configured branch protection rules, you can ensure that your critical branches maintain code quality and follow your team’s established development workflows.

Last updated on