# Create a branch

> Make a branch at another branch, a tag or a commit (from; the default branch when left out).

<div class="g1t-endpoint"><span class="g1t-method" data-method="post">POST</span><code>/repos/{owner}/{name}/branches</code></div>

Needs the Write role or higher, and the repository's rules for creating the branch hold. The name may not be taken, and may not be a folder of another branch's name or hold one (feature cannot sit beside feature/login). To restore a deleted branch, make it again at the commit [`delete_branch`](/reference/api/repositories/delete-branch/) answered with. Returns the new branch and the commit it points to.

The new branch and the commit it points to. `from` is a branch, a tag or a commit, the default branch when left out; to restore a deleted branch, send the `hash` that deleting it answered with. Refused with `404` when `from` names nothing, `409` when the name is taken or is a folder of another branch's name (or holds one), `422` when it is not a valid branch name, and `403` without the Write role or when the repository's rules refuse it. See [Branches](/guides/git/#branches).

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`repository`](/reference/mcp/#repository) with `action` `create_branch`, and the same inputs
- **Scope:** An access token needs [`repo:write`](/guides/authentication/#scopes).

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `owner` | string | Yes | The workspace that owns the repository. |
| `name` | string | Yes | The repository's name. |

## Body parameters

Send a JSON object. Names are `snake_case`, as in responses; the `camelCase` spelling is accepted too.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | The new branch's name, e.g. "feature/login". |
| `from` | string | No | The branch, tag or commit to start it from. The default branch when left out. |

## Example request

```sh
curl -X POST https://api.g1t.sh/repos/flagon-io/hello/branches \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "feature/login",
    "from": "main"
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "name": "feature/login",
  "hash": "9f2c4e1b7a3d5c6e8f0a1b2c3d4e5f6a7b8c9d0e"
}
```

## Errors

A failed request answers with one of these statuses and a body like `{"error": {"code": "not_found", "message": "Repository not found."}}`. See [errors](/reference/api/#errors).

| Status | Code | When |
| --- | --- | --- |
| 401 | `unauthenticated` | A token is required, or the one sent is not valid. |
| 403 | `forbidden` | The token is valid but not allowed to do this, such as a member-only change, or a token without the scope it needs. |
| 404 | `not_found` | It does not exist, or you cannot see it. |
| 409 | `conflict` | The request conflicts with the current state. |
| 422 | `invalid` | The input is not valid. `message` says which field and why. |
