# Create a repository

> Create a repository in one of your workspaces, empty or as a copy of a public git repository elsewhere.

<div class="g1t-endpoint"><span class="g1t-method" data-method="post">POST</span><code>/repos</code></div>

`owner_id` is the id of the person who created the repository. With `import_url`, `default_branch` is the default branch of the repository copied.

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

## Body parameters

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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace` | string | No | The workspace to create it in. May be left out if you belong to exactly one. |
| `name` | string | Yes |  |
| `description` | string | No |  |
| `private` | boolean | No |  |
| `import_url` | string | No | Copy the default branch of a public git repository at this https address, e.g. https://github.com/owner/repo. |

## Example request

```sh
curl -X POST https://api.g1t.sh/repos \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace": "flagon-io",
    "name": "hello-cli",
    "description": "Command-line client for hello.",
    "private": false
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "id": "rep_01m43tk1jhehztx23drs87f5fc",
  "namespace": "flagon-io",
  "name": "hello-cli",
  "description": "Command-line client for hello.",
  "is_private": false,
  "owner_id": "usr_01kkntcg1eeb98j62xjm7eh09p",
  "default_branch": "main",
  "fork_of": null,
  "protected": false,
  "created_at": "2026-10-04T16:05:12.913Z",
  "website": "https://hello.g1t.page",
  "archived_at": null
}
```

## 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 an agent token outside its repository. |
| 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. |
