Edit a branch protection rule for an organization. Only fields that are set will be changed
const url = 'https://gitea.example.com/api/v1/orgs/example/branch_protections/example';const options = { method: 'PATCH', headers: {Authorization: 'Basic <credentials>', 'Content-Type': 'application/json'}, body: '{"approvals_whitelist_teams":["example"],"approvals_whitelist_username":["example"],"block_admin_merge_override":true,"block_on_official_review_requests":true,"block_on_outdated_branch":true,"block_on_rejected_reviews":true,"bypass_allowlist_teams":["example"],"bypass_allowlist_usernames":["example"],"dismiss_stale_approvals":true,"enable_approvals_whitelist":true,"enable_bypass_allowlist":true,"enable_force_push":true,"enable_force_push_allowlist":true,"enable_merge_whitelist":true,"enable_push":true,"enable_push_whitelist":true,"enable_status_check":true,"force_push_allowlist_deploy_keys":true,"force_push_allowlist_teams":["example"],"force_push_allowlist_usernames":["example"],"ignore_stale_approvals":true,"merge_whitelist_teams":["example"],"merge_whitelist_usernames":["example"],"path_rules":[{"can_push":true,"enable_whitelist":true,"exclude_file_patterns":"example","file_patterns":"example","name":"example","push_whitelist_teams":["example"],"push_whitelist_usernames":["example"]}],"priority":1,"protected_file_patterns":"example","push_whitelist_deploy_keys":true,"push_whitelist_teams":["example"],"push_whitelist_usernames":["example"],"require_signed_commits":true,"required_approvals":1,"status_check_contexts":["example"],"unprotected_file_patterns":"example"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request PATCH \ --url https://gitea.example.com/api/v1/orgs/example/branch_protections/example \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --data '{ "approvals_whitelist_teams": [ "example" ], "approvals_whitelist_username": [ "example" ], "block_admin_merge_override": true, "block_on_official_review_requests": true, "block_on_outdated_branch": true, "block_on_rejected_reviews": true, "bypass_allowlist_teams": [ "example" ], "bypass_allowlist_usernames": [ "example" ], "dismiss_stale_approvals": true, "enable_approvals_whitelist": true, "enable_bypass_allowlist": true, "enable_force_push": true, "enable_force_push_allowlist": true, "enable_merge_whitelist": true, "enable_push": true, "enable_push_whitelist": true, "enable_status_check": true, "force_push_allowlist_deploy_keys": true, "force_push_allowlist_teams": [ "example" ], "force_push_allowlist_usernames": [ "example" ], "ignore_stale_approvals": true, "merge_whitelist_teams": [ "example" ], "merge_whitelist_usernames": [ "example" ], "path_rules": [ { "can_push": true, "enable_whitelist": true, "exclude_file_patterns": "example", "file_patterns": "example", "name": "example", "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ] } ], "priority": 1, "protected_file_patterns": "example", "push_whitelist_deploy_keys": true, "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ], "require_signed_commits": true, "required_approvals": 1, "status_check_contexts": [ "example" ], "unprotected_file_patterns": "example" }'Gitea Enterprise only. This endpoint is not part of the community edition.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Name of the organization
Name of protected branch rule
Request Body
Section titled “Request Body”EditBranchProtectionOption options for editing a branch protection
object
For Gitea EE: the ordered path-level write rules; nil leaves them unchanged
PathRule represents a single path-level write rule of a branch protection rule
object
ExcludeFilePatterns excludes matched paths from the scope of this rule
FilePatterns is the scope of this rule (semicolon separated globs)
Examplegenerated
{ "approvals_whitelist_teams": [ "example" ], "approvals_whitelist_username": [ "example" ], "block_admin_merge_override": true, "block_on_official_review_requests": true, "block_on_outdated_branch": true, "block_on_rejected_reviews": true, "bypass_allowlist_teams": [ "example" ], "bypass_allowlist_usernames": [ "example" ], "dismiss_stale_approvals": true, "enable_approvals_whitelist": true, "enable_bypass_allowlist": true, "enable_force_push": true, "enable_force_push_allowlist": true, "enable_merge_whitelist": true, "enable_push": true, "enable_push_whitelist": true, "enable_status_check": true, "force_push_allowlist_deploy_keys": true, "force_push_allowlist_teams": [ "example" ], "force_push_allowlist_usernames": [ "example" ], "ignore_stale_approvals": true, "merge_whitelist_teams": [ "example" ], "merge_whitelist_usernames": [ "example" ], "path_rules": [ { "can_push": true, "enable_whitelist": true, "exclude_file_patterns": "example", "file_patterns": "example", "name": "example", "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ] } ], "priority": 1, "protected_file_patterns": "example", "push_whitelist_deploy_keys": true, "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ], "require_signed_commits": true, "required_approvals": 1, "status_check_contexts": [ "example" ], "unprotected_file_patterns": "example"}Responses
Section titled “Responses”BranchProtection
BranchProtection represents a branch protection for a repository
object
Deprecated: true
For Gitea EE: the ordered path-level write rules of this branch protection rule
PathRule represents a single path-level write rule of a branch protection rule
object
ExcludeFilePatterns excludes matched paths from the scope of this rule
FilePatterns is the scope of this rule (semicolon separated globs)
Priority is the priority of this branch protection rule
RuleName is the name of the branch protection rule
Examplegenerated
{ "approvals_whitelist_teams": [ "example" ], "approvals_whitelist_username": [ "example" ], "block_admin_merge_override": true, "block_on_official_review_requests": true, "block_on_outdated_branch": true, "block_on_rejected_reviews": true, "branch_name": "example", "bypass_allowlist_teams": [ "example" ], "bypass_allowlist_usernames": [ "example" ], "created_at": "2026-04-15T12:00:00Z", "dismiss_stale_approvals": true, "enable_approvals_whitelist": true, "enable_bypass_allowlist": true, "enable_force_push": true, "enable_force_push_allowlist": true, "enable_merge_whitelist": true, "enable_push": true, "enable_push_whitelist": true, "enable_status_check": true, "force_push_allowlist_deploy_keys": true, "force_push_allowlist_teams": [ "example" ], "force_push_allowlist_usernames": [ "example" ], "ignore_stale_approvals": true, "merge_whitelist_teams": [ "example" ], "merge_whitelist_usernames": [ "example" ], "path_rules": [ { "can_push": true, "enable_whitelist": true, "exclude_file_patterns": "example", "file_patterns": "example", "name": "example", "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ] } ], "priority": 1, "protected_file_patterns": "example", "push_whitelist_deploy_keys": true, "push_whitelist_teams": [ "example" ], "push_whitelist_usernames": [ "example" ], "require_signed_commits": true, "required_approvals": 1, "rule_name": "example", "status_check_contexts": [ "example" ], "unprotected_file_patterns": "example", "updated_at": "2026-04-15T12:00:00Z"}APINotFound is a not found empty response
APIValidationError is error format response related to input validation