Skip to content

GitHub: Update branch protection

GitHub repos.reposUpdateBranchProtection: arguments, response, policy and SDK examples.

← Repos operations · Get started

Operation github.repos_update_branch_protection

Provider route: PUT /repos/{owner}/{repo}/branches/{branch}/protection. Alter supplies the connection’s credentials and routing.

Install @alter-ai/sdk @alter-ai/github with npm, or alter-sdk-github with pip. Supply your connected customer’s grant ID and the arguments described below.

import { App } from "@alter-ai/sdk";
import { GitHubIntegration } from "@alter-ai/github";
async function execute(input: Parameters<GitHubIntegration["repos"]["reposUpdateBranchProtection"]>[0]) {
const app = new App({ apiKey: process.env.ALTER_API_KEY! });
try {
const provider = new GitHubIntegration(app, { grantId: process.env.PROVIDER_GRANT_ID! });
const call = await provider.repos.reposUpdateBranchProtection(input);
const result = await call.wait();
return result.bodyJson();
} finally {
await app.close();
}
}
import os
from alter_sdk import App
from alter_sdk_github import GitHubIntegration
async def execute(arguments):
async with App(api_key=os.environ["ALTER_API_KEY"]) as app:
provider = GitHubIntegration(app, {"grant_id": os.environ["PROVIDER_GRANT_ID"]})
call = await provider.repos.repos_update_branch_protection(arguments)
result = await call.wait()
return result.body_json()
FieldTypePresenceDescription and constraints
$objectRootAdditional keys: not allowed
pathobjectRequired within parentAdditional keys: not allowed
path.ownerstringRequired within parent
path.repostringRequired within parent
path.branchstringRequired within parent
bodyobjectRequired within parent
body.allow_deletionsbooleanOptionalAllows 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/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)” in the GitHub Help documentation.
body.allow_force_pushesJSONOptional
body.allow_force_pushes (anyOf 1)booleanAlternativePermits 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/github/administering-a-repository/enabling-force-pushes-to-a-protected-branch)” in the GitHub Help documentation.”
body.allow_force_pushes (anyOf 2)nullAlternative
body.allow_fork_syncingbooleanOptionalWhether 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: false
body.block_creationsbooleanOptionalIf 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`.
body.enforce_adminsJSONRequired within parent
body.enforce_admins (anyOf 1)booleanAlternativeEnforce all configured restrictions for administrators. Set to `true` to enforce required status checks for repository administrators. Set to `null` to disable.
body.enforce_admins (anyOf 2)nullAlternative
body.lock_branchbooleanOptionalWhether to set the branch as read-only. If this is true, users will not be able to push to the branch. Default: `false`.
Default: false
body.required_conversation_resolutionbooleanOptionalRequires 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`.
body.required_linear_historybooleanOptionalEnforces 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.
body.required_pull_request_reviewsJSONRequired within parent
body.required_pull_request_reviews (anyOf 1)objectAlternativeRequire at least one approving review on a pull request, before merging. Set to `null` to disable.
body.required_pull_request_reviews (anyOf 1).bypass_pull_request_allowancesModelOptionalExpand Update pull request review protection — request body — body bypass pull request allowances
body.required_pull_request_reviews (anyOf 1).dismiss_stale_reviewsbooleanOptionalSet to `true` if you want to automatically dismiss approving reviews when someone pushes a new commit.
body.required_pull_request_reviews (anyOf 1).dismissal_restrictionsModelOptionalExpand Update pull request review protection — request body — body dismissal restrictions
body.required_pull_request_reviews (anyOf 1).require_code_owner_reviewsbooleanOptionalBlocks merging pull requests until [code owners](https://docs.github.com/articles/about-code-owners/) review them.
body.required_pull_request_reviews (anyOf 1).require_last_push_approvalbooleanOptionalWhether the most recent push must be approved by someone other than the person who pushed it. Default: `false`.
Default: false
body.required_pull_request_reviews (anyOf 1).required_approving_review_countintegerOptionalSpecify the number of reviewers required to approve pull requests. Use a number between 1 and 6 or 0 to not require reviewers.
body.required_pull_request_reviews (anyOf 2)nullAlternative
body.required_status_checksJSONRequired within parent
body.required_status_checks (anyOf 1)objectAlternativeRequire status checks to pass before merging. Set to `null` to disable.
body.required_status_checks (anyOf 1).checksarrayOptionalThe list of status checks to require in order to merge into this branch.
body.required_status_checks (anyOf 1).checks[]objectEach item
body.required_status_checks (anyOf 1).checks[].app_idintegerOptionalThe 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.
body.required_status_checks (anyOf 1).checks[].contextstringRequired within parentThe name of the required check
body.required_status_checks (anyOf 1).contextsarrayRequired within parentClosing 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.
body.required_status_checks (anyOf 1).contexts[]stringEach item
body.required_status_checks (anyOf 1).strictbooleanRequired within parentRequire branches to be up to date before merging.
body.required_status_checks (anyOf 2)nullAlternative
body.restrictionsJSONRequired within parent
body.restrictions (anyOf 1)objectAlternativeRestrict who can push to the protected branch. User, app, and team `restrictions` are only available for organization-owned repositories. Set to `null` to disable.
body.restrictions (anyOf 1).appsarrayOptionalThe list of app `slug`s with push access
body.restrictions (anyOf 1).apps[]stringEach item
body.restrictions (anyOf 1).teamsarrayRequired within parentThe list of team `slug`s with push access
body.restrictions (anyOf 1).teams[]stringEach item
body.restrictions (anyOf 1).usersarrayRequired within parentThe list of user `login`s with push access
body.restrictions (anyOf 1).users[]stringEach item
body.restrictions (anyOf 2)nullAlternative

Referenced models: Update pull request review protection — request body — body bypass pull request allowances, Update pull request review protection — request body — body dismissal restrictions

Response media type: application/json. The table describes the pinned successful response. Referenced models link to their complete fields.

FieldTypePresenceDescription and constraints
$ModelRootExpand Update branch protection — response body

Referenced models: Update branch protection — response body

6 more schemas are linked from the tables above, on the schema pages.

Update branch protection — response body
FieldTypePresenceDescription and constraints
$objectRootBranch protections protect branches
allow_deletionsobjectOptionalAdditional keys: not allowed
allow_deletions.enabledbooleanRequired within parent
allow_force_pushesobjectOptionalAdditional keys: not allowed
allow_force_pushes.enabledbooleanRequired within parent
allow_fork_syncingobjectOptionalWhether 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.
Additional keys: not allowed
allow_fork_syncing.enabledbooleanOptionalDefault: false
block_creationsobjectOptionalAdditional keys: not allowed
block_creations.enabledbooleanRequired within parent
enforce_adminsobjectOptionalAdditional keys: not allowed
enforce_admins.enabledbooleanRequired within parent
enforce_admins.urlstringRequired within parentFormat: uri
lock_branchobjectOptionalWhether to set the branch as read-only. If this is true, users will not be able to push to the branch.
Additional keys: not allowed
lock_branch.enabledbooleanOptionalDefault: false
required_conversation_resolutionobjectOptionalAdditional keys: not allowed
required_conversation_resolution.enabledbooleanOptional
required_linear_historyobjectOptionalAdditional keys: not allowed
required_linear_history.enabledbooleanRequired within parent
required_pull_request_reviewsobjectOptional
required_pull_request_reviews.bypass_pull_request_allowancesobjectOptional
required_pull_request_reviews.bypass_pull_request_allowances.appsarrayOptional
required_pull_request_reviews.bypass_pull_request_allowances.apps[]ModelEach itemExpand Get an app — response body
required_pull_request_reviews.bypass_pull_request_allowances.teamsarrayRequired within parent
required_pull_request_reviews.bypass_pull_request_allowances.teams[]ModelEach itemExpand List teams — response body — item
required_pull_request_reviews.bypass_pull_request_allowances.usersarrayRequired within parent
required_pull_request_reviews.bypass_pull_request_allowances.users[]ModelEach itemExpand List users — response body — item
required_pull_request_reviews.dismiss_stale_reviewsbooleanOptional
required_pull_request_reviews.dismissal_restrictionsobjectOptional
required_pull_request_reviews.dismissal_restrictions.appsarrayOptional
required_pull_request_reviews.dismissal_restrictions.apps[]ModelEach itemExpand Get an app — response body
required_pull_request_reviews.dismissal_restrictions.teamsarrayRequired within parent
required_pull_request_reviews.dismissal_restrictions.teams[]ModelEach itemExpand List teams — response body — item
required_pull_request_reviews.dismissal_restrictions.teams_urlstringRequired within parentFormat: uri
required_pull_request_reviews.dismissal_restrictions.urlstringRequired within parentFormat: uri
required_pull_request_reviews.dismissal_restrictions.usersarrayRequired within parent
required_pull_request_reviews.dismissal_restrictions.users[]ModelEach itemExpand List users — response body — item
required_pull_request_reviews.dismissal_restrictions.users_urlstringRequired within parentFormat: uri
required_pull_request_reviews.require_code_owner_reviewsbooleanOptional
required_pull_request_reviews.require_last_push_approvalbooleanOptionalWhether the most recent push must be approved by someone other than the person who pushed it.
Default: false
required_pull_request_reviews.required_approving_review_countJSONOptional
required_pull_request_reviews.required_approving_review_count (anyOf 1)integerAlternative
required_pull_request_reviews.required_approving_review_count (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
required_pull_request_reviews.urlstringRequired within parentFormat: uri
required_signaturesobjectOptional
required_signatures.enabledbooleanRequired within parent
required_signatures.urlstringRequired within parentFormat: uri
required_status_checksModelOptionalExpand Get status checks protection — response body
restrictionsModelOptionalExpand Get access restrictions — response body
urlstringRequired within parentFormat: uri

Referenced models: Get access restrictions — response body, Get an app — response body, List users — response body — item, Get status checks protection — response body, List teams — response body — item

Update pull request review protection — request body — body bypass pull request allowances
FieldTypePresenceDescription and constraints
$objectRootAllow specific users, teams, or apps to bypass pull request requirements.
appsarrayOptionalThe list of app `slug`s allowed to bypass pull request requirements.
apps[]stringEach item
teamsarrayOptionalThe list of team `slug`s allowed to bypass pull request requirements.
teams[]stringEach item
usersarrayOptionalThe list of user `login`s allowed to bypass pull request requirements.
users[]stringEach item
Update pull request review protection — request body — body dismissal restrictions
FieldTypePresenceDescription and constraints
$objectRootSpecify 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.
appsarrayOptionalThe list of app `slug`s with dismissal access
apps[]stringEach item
teamsarrayOptionalThe list of team `slug`s with dismissal access
teams[]stringEach item
usersarrayOptionalThe list of user `login`s with dismissal access
users[]stringEach item
List users — response body — item
FieldTypePresenceDescription and constraints
$objectRootA GitHub user.
avatar_urlstringRequired within parentFormat: uri
emailJSONOptional
email (anyOf 1)stringAlternative
email (anyOf 2)nullAlternative
events_urlstringRequired within parent
followers_urlstringRequired within parentFormat: uri
following_urlstringRequired within parent
gists_urlstringRequired within parent
gravatar_idJSONRequired within parent
gravatar_id (anyOf 1)stringAlternative
gravatar_id (anyOf 2)nullAlternative
html_urlstringRequired within parentFormat: uri
idJSONRequired within parent
id (anyOf 1)integerAlternativeFormat: int64
id (anyOf 2)stringAlternativePattern: ^-?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$
loginstringRequired within parent
nameJSONOptional
name (anyOf 1)stringAlternative
name (anyOf 2)nullAlternative
node_idstringRequired within parent
organizations_urlstringRequired within parentFormat: uri
received_events_urlstringRequired within parentFormat: uri
repos_urlstringRequired within parentFormat: uri
site_adminbooleanRequired within parent
starred_atstringOptional
starred_urlstringRequired within parent
subscriptions_urlstringRequired within parentFormat: uri
typestringRequired within parent
urlstringRequired within parentFormat: uri
user_view_typestringOptional
Create a team — response body — parent
FieldTypePresenceDescription and constraints
$JSONRoot
$ (anyOf 1)ModelAlternativeExpand Create a team — response body — parent / type: enterprise, organization
$ (anyOf 2)nullAlternative

Referenced models: Create a team — response body — parent / type: enterprise, organization

SDK function policy ID: github.repos_update_branch_protection. Catalog operation: repos/update-branch-protection. Rules can name either ID; function rules distinguish managed calls and conservatively cover raw calls sharing the route. Existing grant permissions and policy rules apply. wait() returns an immediate result or waits for a required approval; it never approves the request itself. Persist the approval ID to resume after a restart.

Provider errors retain their response; JSON decoding raises ProviderAPIError for provider failures. ManagedOperationError identifies contract/input/retention errors. See error handling and provider-specific behavior. Sensitive input may be refused before approval storage. A decoding error never resubmits a write.

Pinned headers: {"X-GitHub-Api-Version": "2026-03-10", "User-Agent": "Alter", "Accept": "application/vnd.github+json"}

Official provider source

Report an issue with this page

Necessary

Required for sign-in, security, authorization, and remembering your choices.

Always active

Analytics

Helps us understand which product and documentation features are useful.

Performance diagnostics

Uses performance tracing and privacy-masked session replay to diagnose problems.

You can change these choices at any time from Cookie settings.