GitHub v3 REST API

Delete a repository

Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required.

If an organization owner has configured the organization to prevent members from deleting organization-owned
repositories, you will get a 403 Forbidden response.

delete
http://HOSTNAME/api/v3/repos/{owner}/{repo}

Path Parameters

ownerstringrequired
repostringrequired

Response

Response

delete/repos/{owner}/{repo}
 

List branches

get
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches

Query Parameters

protectedboolean

Setting to true returns only protected branches. When set to false, only unprotected branches are returned. Omitting this parameter returns all branches.

per_pageinteger

Results per page (max 100)

Default:30

pageinteger

Page number of the results to fetch.

Default:1

Path Parameters

ownerstringrequired
repostringrequired

Response

application/json

Response

Short Branch

namestringrequired
commitobjectrequired
Show Child Parameters
protectedbooleanrequired
protectionobject

Branch Protection

Show Child Parameters
protection_urlstring(uri)
get/repos/{owner}/{repo}/branches
 
application/json

Get a branch

get
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

application/json

Response

Branch With Protection

Branch With Protection

namestringrequired
commitobjectrequired

Commit

Show Child Parameters
_linksobjectrequired
Show Child Parameters
protectedbooleanrequired
protectionobjectrequired

Branch Protection

Show Child Parameters
protection_urlstring(uri)required
patternstring

Example:"mas*"

required_approving_review_countinteger

Example:1

get/repos/{owner}/{repo}/branches/{branch}
 
application/json

Get 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.

get
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Response

application/json

Response

Branch Protection

Branch Protection

urlstring
enabledboolean
required_status_checksobject

Protected Branch Required Status Check

Show Child Parameters
enforce_adminsobject

Protected Branch Admin Enforced

Show Child Parameters
required_pull_request_reviewsobject

Protected Branch Pull Request Review

Show Child Parameters
restrictionsobject

Branch Restriction Policy

Show Child Parameters
required_linear_historyobject
Show Child Parameters
allow_force_pushesobject
Show Child Parameters
allow_deletionsobject
Show Child Parameters
required_conversation_resolutionobject
Show Child Parameters
namestring

Example:"branch/with/protection"

protection_urlstring

Example:"https://api.github.com/repos/owner-79e94e2d36b3fd06a32bb213/AAA_Public_Repo/branches/branch/with/protection/protection"

required_signaturesobject
Show Child Parameters
get/repos/{owner}/{repo}/branches/{branch}/protection
 
application/json

Update 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.

put
http://HOSTNAME/api/v3/repos/{owner}/{repo}/branches/{branch}/protection

Path Parameters

ownerstringrequired
repostringrequired
branchstringrequired

The name of the branch.

Body

application/json
required_status_checksobject | nullrequired

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

Show Child Parameters
enforce_adminsboolean | nullrequired

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_reviewsobject | nullrequired

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

Show Child Parameters
restrictionsobject | nullrequired

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.

Show Child Parameters
required_linear_historyboolean

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.

allow_force_pushesboolean | null

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."

allow_deletionsboolean

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.

required_conversation_resolutionboolean

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.

contextsarray[string]

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

Response

application/json

Response

Protected Branch

Branch protections protect branches

urlstring(uri)required
required_status_checksobject

Status Check Policy

Show Child Parameters
required_pull_request_reviewsobject
Show Child Parameters
required_signaturesobject
Show Child Parameters
enforce_adminsobject
* Additional properties are NOT allowed.
Show Child Parameters
required_linear_historyobject
* Additional properties are NOT allowed.
Show Child Parameters
allow_force_pushesobject
* Additional properties are NOT allowed.
Show Child Parameters
allow_deletionsobject
* Additional properties are NOT allowed.
Show Child Parameters
restrictionsobject

Branch Restriction Policy

Show Child Parameters
required_conversation_resolutionobject
* Additional properties are NOT allowed.
Show Child Parameters
put/repos/{owner}/{repo}/branches/{branch}/protection

Body

{ "required_status_checks": { "strict": true, "contexts": [ "continuous-integration/travis-ci" ] }, "enforce_admins": true, "required_pull_request_reviews": { "dismissal_restrictions": { "users": [ "octocat" ], "teams": [ "justice-league" ] }, "dismiss_stale_reviews": true, "require_code_owner_reviews": true, "required_approving_review_count": 2, "bypass_pull_request_allowances": { "users": [ "octocat" ], "teams": [ "justice-league" ] } }, "restrictions": { "users": [ "octocat" ], "teams": [ "justice-league" ], "apps": [ "super-ci" ] }, "required_linear_history": true, "allow_force_pushes": true, "allow_deletions": true, "required_conversation_resolution": true }
 
application/json