branch
Creates, updates, deletes, gets or lists a branch resource.
Overview
| Name | branch |
| Type | Resource |
| Id | github.repos.branch |
Fields
The following fields are returned by SELECT queries:
- get_branch
Response
| Name | Datatype | Description |
|---|---|---|
name | string | |
_links | object | |
commit | object | Commit (title: Commit) |
pattern | string | (example: "mas*") |
protected | boolean | |
protection | object | Branch Protection (title: Branch Protection) |
protection_url | string (uri) | |
required_approving_review_count | integer |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_branch | select | owner, repo, branch | ||
rename_branch | exec | owner, repo, branch, new_name | 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. | |
merge_upstream | exec | owner, repo, branch | Sync a branch of a forked repository to keep it up-to-date with the upstream repository. | |
merge | exec | owner, 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.
| Name | Datatype | Description |
|---|---|---|
branch | string | The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API. |
owner | string | The account owner of the repository. The name is not case sensitive. |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
SELECT examples
- get_branch
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
- rename_branch
- merge_upstream
- merge
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 }}"
}'
;
Sync a branch of a forked repository to keep it up-to-date with the upstream repository.
EXEC github.repos.branch.merge_upstream
@owner='{{ owner }}' --required,
@repo='{{ repo }}' --required
@@json=
'{
"branch": "{{ branch }}"
}'
;
Successful Response (The resulting merge commit)
EXEC github.repos.branch.merge
@owner='{{ owner }}' --required,
@repo='{{ repo }}' --required
@@json=
'{
"base": "{{ base }}",
"head": "{{ head }}",
"commit_message": "{{ commit_message }}"
}'
;