---
title: "createRepoBranch"
---

> Documentation Index
> Fetch the complete documentation index at: https://buildrforge.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# createRepoBranch

Path: Forge API › branches

`POST /repos/{repo_id}/branches`

Create a branch at the head of base_branch_id, or at base_commit_id; a body names exactly one of them.

## Path parameters

- `repo_id` (`createRepoBranch.path.repo_id`; string, required)
  - pattern: `^repo_[0-7][0-9a-hjkmnp-tv-z]{25}$`

## Request body

_Required._

Every option has:

- `name` (`<option>.name`; string, required)
  - minLength: `1`

Any of the following, each adding:

- `CreateBranchFromBranch`
  - `base_branch_id` (`CreateBranchFromBranch.base_branch_id`; string, required)
    - pattern: `^branch_[0-7][0-9a-hjkmnp-tv-z]{25}$`
  - `base_commit_id` (`CreateBranchFromBranch.base_commit_id`; unknown, optional)
- `CreateBranchFromCommit`
  - `base_commit_id` (`CreateBranchFromCommit.base_commit_id`; string, required)
    - pattern: `^commit_[0-7][0-9a-hjkmnp-tv-z]{25}$`
  - `base_branch_id` (`CreateBranchFromCommit.base_branch_id`; unknown, optional)

## Example request

```json
{
  "name": "string",
  "base_branch_id": "string",
  "base_commit_id": null
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url '<base-url>/repos/<repo_id>/branches' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "string",
  "base_branch_id": "string",
  "base_commit_id": null
}
'
```

### TypeScript

```typescript
const url = '<base-url>/repos/<repo_id>/branches';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({name: 'string', base_branch_id: 'string', base_commit_id: null})
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "<base-url>/repos/<repo_id>/branches"

payload = {
    "name": "string",
    "base_branch_id": "string",
    "base_commit_id": None
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 201

Branch

#### Example

```json
{
  "id": "string",
  "name": "string",
  "head_commit_id": "string",
  "base_commit_id": "string",
  "deleted_at": "string"
}
```

- `id` (`createRepoBranch.response.201.id`; string, required)
  - pattern: `^branch_[0-7][0-9a-hjkmnp-tv-z]{25}$`
- `name` (`createRepoBranch.response.201.name`; string, required)
  - minLength: `1`
- `head_commit_id` (`createRepoBranch.response.201.head_commit_id`; string, required)
  - pattern: `^commit_[0-7][0-9a-hjkmnp-tv-z]{25}$`
- `base_commit_id` (`createRepoBranch.response.201.base_commit_id`; string, required)
  - pattern: `^commit_[0-7][0-9a-hjkmnp-tv-z]{25}$`
- `deleted_at` (`createRepoBranch.response.201.deleted_at`; any of, required)
  - any of the following: `string`, `null`

### 400

InvalidRequest | RequestBodyTooDeep

#### Example

```json
{
  "_tag": "InvalidRequest",
  "part": "path",
  "issues": [
    {
      "path": [
        "string"
      ],
      "message": "string"
    }
  ]
}
```

Any of the following:

- `InvalidRequestEncoded`
  - `_tag` (`InvalidRequestEncoded._tag`; string, required)
    - one of `"InvalidRequest"`
  - `part` (`InvalidRequestEncoded.part`; string, required)
    - one of `"path"`, `"query"`, `"headers"`, `"body"`
  - `issues` (`InvalidRequestEncoded.issues`; array of object, required)
    - `path` (`InvalidRequestEncoded.issues.path`; array\<any of\>, required)
      - any of the following: `string`, `integer`
    - `message` (`InvalidRequestEncoded.issues.message`; string, required)
- `RequestBodyTooDeepEncoded`
  - `_tag` (`RequestBodyTooDeepEncoded._tag`; string, required)
    - one of `"RequestBodyTooDeep"`
  - `max_depth` (`RequestBodyTooDeepEncoded.max_depth`; integer, required)
    - maximum: `9007199254740991` · minimum: `-9007199254740991`

### 401

InvalidCredentials

#### Example

```json
{
  "_tag": "InvalidCredentials"
}
```

- `_tag` (`createRepoBranch.response.401._tag`; string, required)
  - one of `"InvalidCredentials"`

### 403

Forbidden | ForbiddenOrigin | RequiresPersonalSession | RunBranchRequired

#### Example

```json
{
  "_tag": "Forbidden",
  "message": "string"
}
```

Any of the following:

- `ForbiddenEncoded`
  - `_tag` (`ForbiddenEncoded._tag`; string, required)
    - one of `"Forbidden"`
  - `message` (`ForbiddenEncoded.message`; string, required)
- `ForbiddenOriginEncoded`
  - `_tag` (`ForbiddenOriginEncoded._tag`; string, required)
    - one of `"ForbiddenOrigin"`
- `RequiresPersonalSessionEncoded`
  - `_tag` (`RequiresPersonalSessionEncoded._tag`; string, required)
    - one of `"RequiresPersonalSession"`
- `RunBranchRequiredEncoded`
  - `_tag` (`RunBranchRequiredEncoded._tag`; string, required)
    - one of `"RunBranchRequired"`
  - `branch` (`RunBranchRequiredEncoded.branch`; string, required)
    - minLength: `1`
  - `message` (`RunBranchRequiredEncoded.message`; string, required)

### 404

BranchNotFound | RepoNotFound

#### Example

```json
{
  "_tag": "BranchNotFound",
  "branch": "string"
}
```

Any of the following:

- `BranchNotFoundEncoded`
  - `_tag` (`BranchNotFoundEncoded._tag`; string, required)
    - one of `"BranchNotFound"`
  - `branch` (`BranchNotFoundEncoded.branch`; string, required)
    - minLength: `1`
- `RepoNotFoundEncoded`
  - `_tag` (`RepoNotFoundEncoded._tag`; string, required)
    - one of `"RepoNotFound"`

### 409

BranchExists | RepoArchived

#### Example

```json
{
  "_tag": "BranchExists",
  "branch": "string"
}
```

Any of the following:

- `BranchExistsEncoded`
  - `_tag` (`BranchExistsEncoded._tag`; string, required)
    - one of `"BranchExists"`
  - `branch` (`BranchExistsEncoded.branch`; string, required)
    - minLength: `1`
- `RepoArchivedEncoded`
  - `_tag` (`RepoArchivedEncoded._tag`; string, required)
    - one of `"RepoArchived"`

### 413

WriteTooLarge | RequestBodyTooLarge

#### Example

```json
{
  "_tag": "WriteTooLarge",
  "message": "string"
}
```

Any of the following:

- `WriteTooLargeEncoded`
  - `_tag` (`WriteTooLargeEncoded._tag`; string, required)
    - one of `"WriteTooLarge"`
  - `message` (`WriteTooLargeEncoded.message`; string, required)
- `RequestBodyTooLargeEncoded`
  - `_tag` (`RequestBodyTooLargeEncoded._tag`; string, required)
    - one of `"RequestBodyTooLarge"`
  - `max_bytes` (`RequestBodyTooLargeEncoded.max_bytes`; integer, required)
    - maximum: `9007199254740991` · minimum: `-9007199254740991`

### 429

RateLimited

#### Example

```json
{
  "_tag": "RateLimited"
}
```

- `_tag` (`createRepoBranch.response.429._tag`; string, required)
  - one of `"RateLimited"`

### 500

RepoFailure

#### Example

```json
{
  "_tag": "RepoFailure",
  "reason": "string"
}
```

- `_tag` (`createRepoBranch.response.500._tag`; string, required)
  - one of `"RepoFailure"`
- `reason` (`createRepoBranch.response.500.reason`; string, required)

### 503

RepoBusy | SessionUnavailable | RateLimitUnavailable

#### Example

```json
{
  "_tag": "RepoBusy",
  "message": "string"
}
```

Any of the following:

- `RepoBusyEncoded`
  - `_tag` (`RepoBusyEncoded._tag`; string, required)
    - one of `"RepoBusy"`
  - `message` (`RepoBusyEncoded.message`; string, required)
- `SessionUnavailableEncoded`
  - `_tag` (`SessionUnavailableEncoded._tag`; string, required)
    - one of `"SessionUnavailable"`
- `RateLimitUnavailableEncoded`
  - `_tag` (`RateLimitUnavailableEncoded._tag`; string, required)
    - one of `"RateLimitUnavailable"`


Source: https://buildrforge.com/docs/api/create-repo-branch/index.md
