PUT /repos/{owner}/{repo}/branches/{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 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.

Servers

Path parameters

Name Type Required Description
repo String Yes

The name of the repository without the .git extension. The name is not case sensitive.

branch String Yes

The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.

owner String Yes

The account owner of the repository. The name is not case sensitive.

Request headers

Name Type Required Description
Content-Type String Yes The media type of the request body.

Default value: "application/json"

Request body fields

Name Type Required Description
block_creations Boolean No

If set to true, the restrictions branch protection settings which limits who can push will also block pushes which create new branches, unless the push is initiated by a user, team, or app which has the ability to push. Set to true to restrict new branch creation. Default: false.

required_conversation_resolution Boolean No

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_status_checks Object Yes

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

required_status_checks.contexts[] Array Yes

Closing down notice: 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.

required_status_checks.checks[] Array No

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

required_status_checks.checks[].context String Yes

The name of the required check

required_status_checks.checks[].app_id Integer No

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.

required_status_checks.strict Boolean Yes

Require branches to be up to date before merging.

restrictions Object Yes

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.

restrictions.teams[] Array Yes

The list of team slugs with push access

restrictions.apps[] Array No

The list of app slugs with push access

restrictions.users[] Array Yes

The list of user logins with push access

required_pull_request_reviews Object Yes

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

required_pull_request_reviews.dismiss_stale_reviews Boolean No

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

required_pull_request_reviews.dismissal_restrictions Object No

Specify which users, teams, and apps 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.

required_pull_request_reviews.dismissal_restrictions.teams[] Array No

The list of team slugs with dismissal access

required_pull_request_reviews.dismissal_restrictions.apps[] Array No

The list of app slugs with dismissal access

required_pull_request_reviews.dismissal_restrictions.users[] Array No

The list of user logins with dismissal access

required_pull_request_reviews.bypass_pull_request_allowances Object No

Allow specific users, teams, or apps to bypass pull request requirements.

required_pull_request_reviews.bypass_pull_request_allowances.teams[] Array No

The list of team slugs allowed to bypass pull request requirements.

required_pull_request_reviews.bypass_pull_request_allowances.apps[] Array No

The list of app slugs allowed to bypass pull request requirements.

required_pull_request_reviews.bypass_pull_request_allowances.users[] Array No

The list of user logins allowed to bypass pull request requirements.

required_pull_request_reviews.required_approving_review_count Integer No

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

required_pull_request_reviews.require_last_push_approval Boolean No

Whether the most recent push must be approved by someone other than the person who pushed it. Default: false.

Default value: false

required_pull_request_reviews.require_code_owner_reviews Boolean No

Blocks merging pull requests until code owners review them.

allow_deletions Boolean No

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" in the GitHub Help documentation.

allow_force_pushes Boolean No

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" in the GitHub Help documentation."

required_linear_history Boolean No

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" in the GitHub Help documentation.

lock_branch Boolean No

Whether to set the branch as read-only. If this is true, users will not be able to push to the branch. Default: false.

Default value: false

enforce_admins Boolean Yes

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

allow_fork_syncing Boolean No

Whether users can pull changes from upstream when the branch is locked. Set to true to allow fork syncing. Set to false to prevent fork syncing. Default: false.

Default value: false

How to start integrating

  1. Add HTTP Task to your workflow definition.
  2. Search for the API you want to integrate with and click on the name.
    • This loads the API reference documentation and prepares the Http request settings.
  3. Click Test request to test run your request to the API and see the API's response.