Branch¶
Branches isolate development and release lines. With the API you can list, create, and delete branches, read a single branch, and manage protected branch rules (which branches forbid force pushes and deletion, and who may push to them).
Objects¶
| Object | Description | Related endpoint |
|---|---|---|
| Branch | Branch name, commit SHA, protection status, and more | Get all project branches |
| Protected branch rule | Matching branches (wildcards supported), push permissions, and merge permissions | Get the protected branch rule list |
Identification¶
- Repositories are identified by
owner+repo, branches by the path parameternameorbranch. - Protection rules are identified by
wildcard, which can be written as a wildcard pattern matching a set of branches.
Common tasks¶
| Task | Endpoint |
|---|---|
| List all branches | GET /api/v5/repos/{owner}/{repo}/branches |
| Create a branch | POST /api/v5/repos/{owner}/{repo}/branches |
| Get a single branch | GET /api/v5/repos/{owner}/{repo}/branches/{branch} |
| Delete a branch | DELETE /api/v5/repos/{owner}/{repo}/branches/{name} |
| List protected branch rules | GET /api/v5/repos/{owner}/{repo}/protect_branches |
| Create a protected branch rule | PUT /api/v5/repos/{owner}/{repo}/branches/setting/new |
| Update a protected branch rule | PUT /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting |
| Delete a protected branch rule | DELETE /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting |
Notes¶
- Creating a protection rule uses the fixed literal
new:PUT …/branches/setting/new, notbranches/{wildcard}/setting. Only updating and deleting use{wildcard}. - The protection rule list endpoint is
GET …/protect_branches(underscore), which is not the same path family as the branch list…/branches. - Deleting a branch uses
{name}while reading a single branch uses{branch}. The two placeholder names differ but mean the same thing, so be careful when copying paths. - Branch-related permissions (push rules, permission modes) live in the repositories group; this group only covers branches themselves and protection rules.
Endpoint list¶
This module contains 8 endpoints in total.
| # | Endpoint | Method and path | Description |
|---|---|---|---|
| 1 | Get all project branches | GET /api/v5/repos/{owner}/{repo}/branches |
Retrieves all branches in the specified project (repository). Supports sorting by name or update time and paginated queries, and returns each branch's name, description, target… |
| 2 | Create a branch | POST /api/v5/repos/{owner}/{repo}/branches |
Creates a new branch in the specified repository. You can specify the branch starting point, the new branch name, and a description. On success it returns the new branch's name, description, target commit… |
| 3 | Delete a branch | DELETE /api/v5/repos/{owner}/{repo}/branches/{name} |
Deletes the specified branch in the specified repository. On success the target branch is removed and the response body is empty. |
| 4 | Get a single branch | GET /api/v5/repos/{owner}/{repo}/branches/{branch} |
Retrieves a single branch in the specified repository, returning the branch name, description, details of the commit it targets, and whether it is merged, protected, or the default… |
| 5 | Create a protected branch rule | PUT /api/v5/repos/{owner}/{repo}/branches/setting/new |
Creates a protected branch rule for the specified repository. By setting a branch or wildcard and specifying the members who may push code and who may merge pull requests… |
| 6 | Delete a protected branch rule | DELETE /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting |
Deletes the protected branch rule of the specified branch in the specified repository. On success it returns an empty response body; if the branch has no protection rule, it returns an error message… |
| 7 | Get the protected branch rule list | GET /api/v5/repos/{owner}/{repo}/protect_branches |
Retrieves the protected branch rule list of the specified repository, returning each rule's branch name, update time, the users allowed to push and merge, and the permissions of each role (open… |
| 8 | Update a protected branch rule | PUT /api/v5/repos/{owner}/{repo}/branches/{wildcard}/setting |
Updates the rule of a specific protected branch in the specified repository. By setting the members who may push code and the members who may merge requests, it controls push and merge permissions. |
Markdown source: View on AtomGit·Content from the open-source project gitcode-dev/atomgit-api-doc