Skip to main content

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.

PUT/repos/{owner}/{repo}/branches/{branch}/protection
Source
github-v3-rest.json
Revision
f5f067c1e6f6
Active snapshot
85e53e3d0d65

Request

Path Parameters
owner string
required
repo string
required
branch string
required

The name of the branch.

Body Params
required
application/jsonobject
allow_deletions boolean
optional

Allows 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.

allow_force_pushes boolean
optionalnullable

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."

contexts array[string]
optional

The list of status checks to require in order to merge into this branch.

enforce_admins boolean
requirednullable

Enforce all configured restrictions for administrators. Set to `true` to enforce required status checks for repository administrators. Set to `null` to disable.

required_conversation_resolution boolean
optional

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`.

required_linear_history boolean
optional

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 object
requirednullable

Require at least one approving review on a pull request, before merging. Set to `null` to disable.

dismiss_stale_reviews boolean
optional

Set to `true` if you want to automatically dismiss approving reviews when someone pushes a new commit.

dismissal_restrictions object
optional

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.

teams array[string]
optional

The list of team `slug`s with dismissal access

users array[string]
optional

The list of user `login`s with dismissal access

require_code_owner_reviews boolean
optional

Blocks merging pull requests until [code owners](https://docs.github.com/articles/about-code-owners/) review them.

required_approving_review_count integer
optional

Specify the number of reviewers required to approve pull requests. Use a number between 1 and 6.

required_status_checks object
requirednullable

Require status checks to pass before merging. Set to `null` to disable.

checks array[object]
optional

The list of status checks to require in order to merge into this branch.

items object
app_id integer
optional

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.

context string
required

The name of the required check

contexts array[string]
requireddeprecated

**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.

strict boolean
required

Require branches to be up to date before merging.

restrictions object
requirednullable

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.

apps array[string]
optional

The list of app `slug`s with push access

teams array[string]
required

The list of team `slug`s with push access

users array[string]
required

The list of user `login`s with push access

Responses

application/json Protected Branch object

Response

allow_deletions object
optional
enabled boolean
required
allow_force_pushes object
optional
enabled boolean
required
enforce_admins object
optional
enabled boolean
required
url string<uri>
required
required_conversation_resolution object
optional
enabled boolean
optional
required_linear_history object
optional
enabled boolean
required
required_pull_request_reviews object
optional
dismiss_stale_reviews boolean
optional
dismissal_restrictions object
optional
teams array[Team object]
required
teams_url string<uri>
required
url string<uri>
required
users array[Simple User object]
required
users_url string<uri>
required
require_code_owner_reviews boolean
optional
required_approving_review_count integer
optional
url string<uri>
required
required_signatures object
optional
enabled boolean
required

Example: true

url string<uri>
required

Example: https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_signatures

required_status_checks Status Check Policy object
optional

Status Check Policy

contexts array[string]
required
Example:
[
  "continuous-integration/travis-ci"
]
contexts_url string<uri>
required
Example:
https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts
strict boolean
required

Example: true

url string<uri>
required
Example:
https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks
restrictions Branch Restriction Policy object
optional

Branch Restriction Policy

apps array[object]
required
items object
created_at string
optional
description string
optional
events array
optional
external_url string
optional
html_url string
optional
id integer
optional
name string
optional
node_id string
optional
owner object
optional
permissions object
optional
slug string
optional
updated_at string
optional
apps_url string<uri>
required
teams array[object]
required
items object
description string
optionalnullable
html_url string
optional
id integer
optional
members_url string
optional
name string
optional
node_id string
optional
parent string
optionalnullable
permission string
optional
privacy string
optional
repositories_url string
optional
slug string
optional
url string
optional
teams_url string<uri>
required
url string<uri>
required
users array[object]
required
items object
avatar_url string
optional
events_url string
optional
followers_url string
optional
following_url string
optional
gists_url string
optional
gravatar_id string
optional
html_url string
optional
id integer
optional
login string
optional
node_id string
optional
organizations_url string
optional
received_events_url string
optional
repos_url string
optional
site_admin boolean
optional
starred_url string
optional
subscriptions_url string
optional
type string
optional
url string
optional
users_url string<uri>
required
url string<uri>
required
application/json Basic Error object

Forbidden

documentation_url string
optional
message string
optional
status string
optional
url string
optional
application/json Basic Error object

Resource not found

documentation_url string
optional
message string
optional
status string
optional
url string
optional
application/json Validation Error Simple object

Validation failed

documentation_url string
required
errors array[string]
optional
message string
required