## Link a repository (tenant:forge:write and maintainer, or tenant:forge:admin)

`POST /api/forge/v1/projects/{key}/repositories`

Module: Forge · operationId: `addForgeRepository` · Tag: Repositories · Auth: access token (`Authorization: Bearer <accessToken>`)

Requires `tenant:forge:admin`, or `tenant:forge:write` and project role maintainer or admin. The first repository becomes the default. Writes `forge.config.updated`.

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `key` | path | string | yes | Project key (e.g. APP) |

### Request body

`application/json` (required)

- `fullName` (string, required): owner/name of the repository
- `baseBranch` (string, nullable): Base branch for new branches; null = the repository's default branch
- `isDefault` (boolean): Make it the default repository (the first one always is)
- `provider` (string): Repository provider key: github, gitlab or gitlab@<host>. forge checks only the syntax; scm decides whether the provider is known and configured (400 `fullName` when its installations do not reach the repository, 503 when scm cannot be asked or the provider is not configured) (default `"github"`)

Example:

```json
{
  "fullName": "mbcomdev/demo-app",
  "isDefault": true
}
```

### Responses

- **201** Linked (`application/json`)
- **400** Error (`application/json`)
- **403** Error (`application/json`)
- **404** Error (`application/json`)
- **409** Error (`application/json`)

Fields of the 201 answer:

- `createdAt` (string (date-time), required): When it was linked
- `fullName` (string, required): owner/name
- `id` (string (uuid), required): Repository link id
- `isDefault` (boolean, required): The default repository of the project
- `provider` (string, required): Repository provider key: github, gitlab or gitlab@<host> (self-managed GitLab)
- `baseBranch` (string, nullable): Base branch for new branches; null = the repository's default branch

Example 201 answer:

```json
{
  "baseBranch": null,
  "createdAt": "2026-09-23T09:10:00Z",
  "fullName": "mbcomdev/demo-app",
  "id": "4b5c6d7e-8f9a-4b1c-8d2e-3f4a5b6c7d01",
  "isDefault": true,
  "provider": "github"
}
```

### Example request

```bash
curl -X POST 'https://api.mbcom.cloud/api/forge/v1/projects/string/repositories' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"fullName":"mbcomdev/demo-app","isDefault":true}'
```
