Skip to main content

branch_protection

Creates, updates, deletes, gets or lists a branch_protection resource.

Overview

Namebranch_protection
TypeResource
Idgithub.repos.branch_protection

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
namestring (example: "branch/with/protection")
allow_deletionsobject
allow_force_pushesobject
allow_fork_syncingobjectWhether 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.
block_creationsobject
enabledboolean
enforce_adminsobjectProtected Branch Admin Enforced (title: Protected Branch Admin Enforced)
lock_branchobjectWhether to set the branch as read-only. If this is true, users will not be able to push to the branch.
protection_urlstring (example: "https://api.github.com/repos/owner-79e94e2d36b3fd06a32bb213/AAA_Public_Repo/branches/branch/with/protection/protection")
required_conversation_resolutionobject
required_linear_historyobject
required_pull_request_reviewsobjectProtected Branch Pull Request Review (title: Protected Branch Pull Request Review)
required_signaturesobject
required_status_checksobjectProtected Branch Required Status Check (title: Protected Branch Required Status Check)
restrictionsobjectBranch Restriction Policy (title: Branch Restriction Policy)
urlstring

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_branch_protectionselectowner, repo, branchProtected 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.
update_branch_protectionreplaceowner, repo, branch, required_status_checks, enforce_admins, required_pull_request_reviews, restrictionsProtected 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.
delete_branch_protectiondeleteowner, repo, branchProtected 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.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
branchstringThe name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API.
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.

SELECT examples

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.

SELECT
name,
allow_deletions,
allow_force_pushes,
allow_fork_syncing,
block_creations,
enabled,
enforce_admins,
lock_branch,
protection_url,
required_conversation_resolution,
required_linear_history,
required_pull_request_reviews,
required_signatures,
required_status_checks,
restrictions,
url
FROM github.repos.branch_protection
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND branch = '{{ branch }}' -- required
;

REPLACE examples

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.

REPLACE github.repos.branch_protection
SET
required_status_checks = '{{ required_status_checks }}',
enforce_admins = {{ enforce_admins }},
required_pull_request_reviews = '{{ required_pull_request_reviews }}',
restrictions = '{{ restrictions }}',
required_linear_history = {{ required_linear_history }},
allow_force_pushes = {{ allow_force_pushes }},
allow_deletions = {{ allow_deletions }},
block_creations = {{ block_creations }},
required_conversation_resolution = {{ required_conversation_resolution }},
lock_branch = {{ lock_branch }},
allow_fork_syncing = {{ allow_fork_syncing }}
WHERE
owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND branch = '{{ branch }}' --required
AND required_status_checks = '{{ required_status_checks }}' --required
AND enforce_admins = {{ enforce_admins }} --required
AND required_pull_request_reviews = '{{ required_pull_request_reviews }}' --required
AND restrictions = '{{ restrictions }}' --required
RETURNING
allow_deletions,
allow_force_pushes,
allow_fork_syncing,
block_creations,
enforce_admins,
lock_branch,
required_conversation_resolution,
required_linear_history,
required_pull_request_reviews,
required_signatures,
required_status_checks,
restrictions,
url;

DELETE examples

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.

DELETE FROM github.repos.branch_protection
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND branch = '{{ branch }}' --required
;