# Fork a repository

> Fork a repository: copy it into a workspace you can create repositories in, as a new repository that remembers the one it came from (its parent).

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

Anyone who can read a public repository may fork it; a private one only when its admins allow forking (allow_forking on [`update_repo`](/reference/api/repositories/update-repo/)). A fork is exactly as visible as its parent: a public repository's fork is public, a private one's private. Only its code comes with it: the default branch, or every branch and tag with default_branch_only false. Its project starts with the parent project's description. Its issues, pull requests, settings, rulesets, secrets, variables, webhooks, environments and deployments stay behind; issues are off in the fork, and Actions is off until an admin of the fork turns it on. Its full size counts toward the destination workspace's storage, and a free workspace takes a private fork only while its private storage has room. workspace is the destination's slug: your personal workspace when left out. name is the parent's when left out. Returns the fork, with parent naming the repository it came from.

The new fork, with `parent` naming the repository it came from. Refused with `403` when the repository is private and its admins have not allowed forking, or when you cannot create repositories in the workspace; `409` when the workspace already has a repository of that name (give another `name`); `402` when a free workspace's private storage has no room for a private fork. Its code and description are copied; nothing else is. See [Forking a repository](/guides/forking-repositories/) and [Forks](/concepts/forks/).

- **Authentication:** Required. Send an [access token](/reference/api/#authentication) as `Authorization: Bearer`.
- **MCP tool:** [`repository`](/reference/mcp/#repository) with `action` `fork`, 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 |
| --- | --- | --- | --- |
| `workspace` | string | No | The slug of the workspace to fork it into, e.g. "flagon-io". Your personal workspace when left out. |
| `name` | string | No | The fork's name; the repository's own when left out. |
| `default_branch_only` | boolean | No | Copy only the default branch (the default). false copies every branch and tag. |

## Example request

```sh
curl -X POST https://api.g1t.sh/repos/flagon-io/hello/forks \
  -H "Authorization: Bearer $G1T_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "workspace": "ada",
    "default_branch_only": true
  }'
```

## Example response

A successful request answers `200` with:

```json
{
  "id": "rep_01m4b7k2v9c3tq8x5n6d0fr1hz",
  "namespace": "ada",
  "name": "hello",
  "is_private": false,
  "owner_id": "usr_01kq3r8w2m6vd5e9t0hy7jx4cb",
  "default_branch": "main",
  "fork_of": null,
  "parent_id": "rep_01m3m5q6p0e2qaw6mmjahk0qrr",
  "parent": {
    "namespace": "flagon-io",
    "name": "hello"
  },
  "allow_forking": false,
  "protected": false,
  "created_at": "2026-10-14T09:30:12.418Z",
  "website": null,
  "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. |
| 402 | `payment_required` | The workspace cannot start this work: it needs the g1t plan or a card check, or it is at a limit. See [usage and billing](/guides/usage-and-billing/#when-work-is-stopped). |
| 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. |
