Get branch

GET /repos/:owner/:repo/branches/:branch

Response

Status: 200 OK

{"name":"master","commit":{"sha":"7fd1a60b01f91b314f59955a4e4d4e80d8edf11d","commit":{"author":{"name":"The Octocat","date":"2012-03-06T15:06:50-08:00","email":"octocat@nowhere.com"},"url":"https://api.github.com/repos/octocat/Hello-World/git/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d","message":"Merge pull request #6 from Spaceghost/patch-1\n\nNew line at end of file.","tree":{"sha":"b4eecafa9be2f2006ce1b709d6857b07069b4608","url":"https://api.github.com/repos/octocat/Hello-World/git/trees/b4eecafa9be2f2006ce1b709d6857b07069b4608"},"committer":{"name":"The Octocat","date":"2012-03-06T15:06:50-08:00","email":"octocat@nowhere.com"},"verification":{"verified":false,"reason":"unsigned","signature":null,"payload":null}},"author":{"gravatar_id":"","avatar_url":"https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/octocat","id":583231,"login":"octocat"},"parents":[{"sha":"553c2077f0edc3d5dc5d17262f6aa498e69d6f8e","url":"https://api.github.com/repos/octocat/Hello-World/commits/553c2077f0edc3d5dc5d17262f6aa498e69d6f8e"},{"sha":"762941318ee16e59dabbacb1b4049eec22f0d303","url":"https://api.github.com/repos/octocat/Hello-World/commits/762941318ee16e59dabbacb1b4049eec22f0d303"}],"url":"https://api.github.com/repos/octocat/Hello-World/commits/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d","committer":{"gravatar_id":"","avatar_url":"https://secure.gravatar.com/avatar/7ad39074b0584bc555d0417ae3e7d974?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","url":"https://api.github.com/users/octocat","id":583231,"login":"octocat"}},"_links":{"html":"https://github.com/octocat/Hello-World/tree/master","self":"https://api.github.com/repos/octocat/Hello-World/branches/master"},"protected":true,"protection_url":"https://api.github.com/repos/octocat/Hello-World/branches/master/protection"}

Get branch protection

Note: The Protected Branches API now has a setting for requiring a specified number of approving pull request reviews before merging. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.luke-cage-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

Update branch protection

Note: The Protected Branches API now has a setting for requiring a specified number of approving pull request reviews before merging. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.luke-cage-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

Protecting a branch requires admin or owner permissions to the repository.

PUT /repos/:owner/:repo/branches/:branch/protection

Parameters

Name

Type

Description

required_status_checks

object

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

enforce_admins

boolean

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

required_pull_request_reviews

object

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

restrictions

object

Required. Restrict who can push to this branch. Team and user restrictions are only available for organization-owned repositories. Set to null to disable.

The required_status_checks object must have the following keys:

Name

Type

Description

strict

boolean

Required. Require branches to be up to date before merging.

contexts

array

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

The required_pull_request_reviews object must have the following keys:

Name

Type

Description

dismissal_restrictions

object

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.

dismiss_stale_reviews

boolean

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

require_code_owner_reviews

boolean

Blocks merging pull requests until code owners review them.

required_approving_review_count

integer

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

The dismissal_restrictions object must have the following keys:

Name

Type

Description

users

array

The list of user logins with dismissal access

teams

array

The list of team slugs with dismissal access

Note: Passing new arrays of users and teams replaces their previous values.

Remove required status checks contexts of protected branch

Example

["continuous-integration/jenkins"]

Response

Status: 200 OK

["continuous-integration/travis-ci"]

Get pull request review enforcement of protected branch

Note: The Protected Branches API now has a setting for requiring a specified number of approving pull request reviews before merging. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.luke-cage-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

GET /repos/:owner/:repo/branches/:branch/protection/required_pull_request_reviews

Update pull request review enforcement of protected branch

Note: The Protected Branches API now has a setting for requiring a specified number of approving pull request reviews before merging. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.luke-cage-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

Updating pull request review enforcement requires admin or owner permissions to the repository and branch protection to be enabled.

Parameters

The object passed can have the following keys:

Name

Type

Description

dismissal_restrictions

object

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.

dismiss_stale_reviews

boolean

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

require_code_owner_reviews

boolean

Blocks merging pull requests until code owners have reviewed.

required_approving_review_count

integer

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

The dismissal_restrictions object must have the following keys:

Name

Type

Description

users

array

The list of user logins with dismissal access

teams

array

The list of team slugs with dismissal access

Note: Passing new arrays of users and teams replaces their previous values.

Remove pull request review enforcement of protected branch

Get required signatures of protected branch

Note: Protected Branches API can now manage a setting for requiring signed commits. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.zzzax-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

When authenticated with admin or owner permissions to the repository, you can use this endpoint to check whether a branch requires signed commits. An enabled status of true indicates you must sign commits on this branch. For more information, see Signing commits with GPG in GitHub Help.

Note: You must enable branch protection to require signed commits.

GET /repos/:owner/:repo/branches/:branch/protection/required_signatures

Response

Add required signatures of protected branch

Note: Protected Branches API can now manage a setting for requiring signed commits. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.zzzax-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

When authenticated with admin or owner permissions to the repository, you can use this endpoint to require signed commits on a branch. You must enable branch protection to require signed commits.

Response

Remove required signatures of protected branch

Note: Protected Branches API can now manage a setting for requiring signed commits. This feature is currently available for developers to preview. See the blog post for full details. To access the API during the preview period, you must provide a custom media type in the Accept header:

application/vnd.github.zzzax-preview+json

Warning: The API may change without advance notice during the preview period. Preview features are not supported for production use. If you experience any issues, contact GitHub support.

When authenticated with admin or owner permissions to the repository, you can use this endpoint to disable required signed commits on a branch. You must enable branch protection to require signed commits.