Skip to main content

branch

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

Overview

Namebranch
TypeResource
Idgithub.repos.branch

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
namestring
_linksobject
commitobjectCommit (title: Commit)
patternstring (example: "mas*")
protectedboolean
protectionobjectBranch Protection (title: Branch Protection)
protection_urlstring (uri)
required_approving_review_countinteger

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_branchselectowner, repo, branch
rename_branchexecowner, repo, branch, new_nameRenames a branch in a repository.

> [!NOTE]
> Although the API responds immediately, the branch rename process might take some extra time to complete in the background. You won't be able to push to the old branch name while the rename process is in progress. For more information, see "Renaming a branch".

The authenticated user must have push access to the branch. If the branch is the default branch, the authenticated user must also have admin or owner permissions.

In order to rename the default branch, fine-grained access tokens also need the administration:write repository permission.
merge_upstreamexecowner, repo, branchSync a branch of a forked repository to keep it up-to-date with the upstream repository.
mergeexecowner, repo, base, head

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

Response

SELECT
name,
_links,
commit,
pattern,
protected,
protection,
protection_url,
required_approving_review_count
FROM github.repos.branch
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND branch = '{{ branch }}' -- required
;

Lifecycle Methods

Renames a branch in a repository.

> [!NOTE]
> Although the API responds immediately, the branch rename process might take some extra time to complete in the background. You won't be able to push to the old branch name while the rename process is in progress. For more information, see "Renaming a branch".

The authenticated user must have push access to the branch. If the branch is the default branch, the authenticated user must also have admin or owner permissions.

In order to rename the default branch, fine-grained access tokens also need the administration:write repository permission.

EXEC github.repos.branch.rename_branch 
@owner='{{ owner }}' --required,
@repo='{{ repo }}' --required,
@branch='{{ branch }}' --required
@@json=
'{
"new_name": "{{ new_name }}"
}'
;