Update branch protection
Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see [GitHub's products](https://docs.github.com/github/getting-started-with-github/githubs-products) in the GitHub Help documentation. Protecting a branch requires admin or owner permissions to the repository. **Note**: Passing new arrays of `users` and `teams` replaces their previous values. **Note**: The list of users, apps, and teams in total is limited to 100 items.
/repos/{owner}/{repo}/branches/{branch}/protection- Source
github-v3-rest.json- Revision
f5f067c1e6f6- Active snapshot
85e53e3d0d65
Request
Path Parameters
- owner stringrequired
- repo stringrequired
- branch stringrequired
The name of the branch.
Body Params
requiredAllows deletion of the protected branch by anyone with write access to the repository. Set to `false` to prevent deletion of the protected branch. Default: `false`. For more information, see "[Enabling force pushes to a protected branch](https://docs.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)" in the GitHub Help documentation.
Permits force pushes to the protected branch by anyone with write access to the repository. Set to `true` to allow force pushes. Set to `false` or `null` to block force pushes. Default: `false`. For more information, see "[Enabling force pushes to a protected branch](https://docs.github.com/en/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)" in the GitHub Help documentation."
The list of status checks to require in order to merge into this branch.
Enforce all configured restrictions for administrators. Set to `true` to enforce required status checks for repository administrators. Set to `null` to disable.
Requires all conversations on code to be resolved before a pull request can be merged into a branch that matches this rule. Set to `false` to disable. Default: `false`.
Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch. Set to `true` to enforce a linear commit history. Set to `false` to disable a linear commit Git history. Your repository must allow squash merging or rebase merging before you can enable a linear commit history. Default: `false`. For more information, see "[Requiring a linear commit history](https://docs.github.com/github/administering-a-repository/requiring-a-linear-commit-history)" in the GitHub Help documentation.
required_pull_request_reviews objectrequirednullable Require at least one approving review on a pull request, before merging. Set to `null` to disable.
Require at least one approving review on a pull request, before merging. Set to `null` to disable.
Set to `true` if you want to automatically dismiss approving reviews when someone pushes a new commit.
dismissal_restrictions objectoptionalSpecify which users and teams can dismiss pull request reviews. Pass an empty `dismissal_restrictions` object to disable. User and team `dismissal_restrictions` are only available for organization-owned repositories. Omit this parameter for personal repositories.
Specify which users and teams can dismiss pull request reviews. Pass an empty `dismissal_restrictions` object to disable. User and team `dismissal_restrictions` are only available for organization-owned repositories. Omit this parameter for personal repositories.
The list of team `slug`s with dismissal access
The list of user `login`s with dismissal access
Blocks merging pull requests until [code owners](https://docs.github.com/articles/about-code-owners/) review them.
Specify the number of reviewers required to approve pull requests. Use a number between 1 and 6.
required_status_checks objectrequirednullable Require status checks to pass before merging. Set to `null` to disable.
Require status checks to pass before merging. Set to `null` to disable.
checks array[object]optionalThe list of status checks to require in order to merge into this branch.
The list of status checks to require in order to merge into this branch.
items object
The ID of the GitHub App that must provide this check. Omit this field to automatically select the GitHub App that has recently provided this check, or any app if it was not set by a GitHub App. Pass -1 to explicitly allow any app to set the status.
The name of the required check
**Deprecated**: The list of status checks to require in order to merge into this branch. If any of these checks have recently been set by a particular GitHub App, they will be required to come from that app in future for the branch to merge. Use `checks` instead of `contexts` for more fine-grained control.
Require branches to be up to date before merging.
restrictions objectrequirednullable Restrict who can push to the protected branch. User, app, and team `restrictions` are only available for organization-owned repositories. Set to `null` to disable.
Restrict who can push to the protected branch. User, app, and team `restrictions` are only available for organization-owned repositories. Set to `null` to disable.
The list of app `slug`s with push access
The list of team `slug`s with push access
The list of user `login`s with push access
Responses
Response
allow_deletions objectoptional
allow_force_pushes objectoptional
enforce_admins objectoptional
required_conversation_resolution objectoptional
required_linear_history objectoptional
required_pull_request_reviews objectoptional
dismissal_restrictions objectoptional
required_signatures objectoptional
Example: true
Example: https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_signatures
required_status_checks Status Check Policy objectoptionalStatus Check Policy
Status Check Policy
[
"continuous-integration/travis-ci"
]https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contextsExample: true
https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks restrictions Branch Restriction Policy objectoptionalBranch Restriction Policy
Branch Restriction Policy
apps array[object]required
items object
teams array[object]required
items object
users array[object]required
items object
Forbidden
Resource not found
Validation failed