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

# store.createRepo()

> Create a new repository with optional custom ID, default branch, Git Sync configuration, or a fork from an existing repository.

> [!WARNING]
>
> This page documents the earlier Code Storage SDKs: `@pierre/storage`, `pierre-storage`, and
> `code-storage-go`. New code uses the [Pierre SDK](https://code.storage/docs/sdks.md). To move code to the new SDK, use the
> [`pierre-migrate`
> skill](https://github.com/pierrecomputer/skills/tree/main/skills/pierre-migrate).

```typescript TypeScript theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
// Basic repository creation (defaults to 'main' branch)
const repo = await store.createRepo();

// With custom ID
const repo = await store.createRepo({
  id: 'my-custom-repo',
});

// With custom default branch
const repo = await store.createRepo({
  id: 'my-custom-repo',
  defaultBranch: 'develop',
});

// With namespacing
const repo = await store.createRepo({
  id: 'production/api-service',
  defaultBranch: 'production',
});

// Fork from existing repository
const fork = await store.createRepo({
  id: 'my-fork',
  baseRepo: {
    id: 'source-repo', // Repository to fork from
    ref: 'main', // Optional: branch to fork from
  },
});
```

```python Python theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
import os

from pierre_storage import GitStorage

storage = GitStorage({
    "name": os.environ["PIERRE_ORG"],
    "key": os.environ["PIERRE_PRIVATE_KEY"],
})

repo = await storage.create_repo()
print(repo.id)  # e.g., '123e4567-e89b-12d3-a456-426614174000'

custom_repo = await storage.create_repo(id="my-custom-repo")
print(custom_repo.id)  # 'my-custom-repo'

# Git sync (GitHub example)
github_repo = await storage.create_repo(
    id="my-synced-repo",
    base_repo={
        "owner": "octocat",
        "name": "Hello-World",
        "default_branch": "main",  # optional
    },
)
# This repository will sync with github.com/octocat/Hello-World

# Fork from existing repository
fork = await storage.create_repo(
    id="my-fork",
    base_repo={
        "id": "source-repo",  # Repository to fork from
        "ref": "main",        # Optional: branch to fork from
    },
)
```

```go Go theme={null} theme={"theme":{"light":"github-light","dark":"min-dark"}}
ctx := context.Background()

// Create a new repository
repo, err := client.CreateRepo(ctx, storage.CreateRepoOptions{})

// Create a repository with a custom ID
customRepo, err := client.CreateRepo(ctx, storage.CreateRepoOptions{
	ID: "my-custom-repo",
})

// Create a repository with Git sync (GitHub example)
githubRepo, err := client.CreateRepo(ctx, storage.CreateRepoOptions{
	ID: "my-synced-repo",
	BaseRepo: storage.GitHubBaseRepo{
		Owner:         "octocat",
		Name:          "Hello-World",
		DefaultBranch: "main",
	},
})

// Fork from an existing repository
fork, err := client.CreateRepo(ctx, storage.CreateRepoOptions{
	ID: "my-fork",
	BaseRepo: storage.ForkBaseRepo{
		ID:  "source-repo",
		Ref: "main",
	},
})
```

## Options

**id** `string`

Repository ID. If not provided, a UUID will be auto-generated. Supports namespacing with `/`
(e.g., `team/project-alpha`).

**defaultBranch** `string`

Default branch name for the repository. Defaults to `main`, or to the source repository's default
branch when `baseRepo` forks an existing repository.

**baseRepo** `object`

Configuration for Git Sync or forking from an existing repository. See below for structure.

**ttl** `string`

Token TTL for this invocation in seconds. Defaults to 1 hour when omitted for this call.

## BaseRepo for Git Sync

Use this structure to sync with a GitHub repository:

**owner** `string` *required*

GitHub repository owner (username or organization).

**name** `string` *required*

GitHub repository name.

**defaultBranch** `string`

GitHub repository's default branch.

> When `baseRepo` contains `owner` and `name`, Code Storage links the repository to an external Git
> provider for syncing. See the [GitHub Sync guide](https://code.storage/docs/repos/github-sync.md) for details.

> Generic Git providers such as GitLab, Bitbucket, Gitea, Forgejo, Codeberg, and SourceHut use the
> same repository creation flow at the HTTP API layer. After creating the repo, configure
> credentials with [Git credentials](https://code.storage/docs/api/repos/git-credential-create.md).

## BaseRepo for Forking

Use this structure to fork from an existing Code Storage repository:

**id** `string` *required*

The source repository ID to fork from.

**ref** `string`

Branch or tag name to fork from. Forks the tip of this ref.

**sha** `string`

Exact commit SHA to fork at. Overrides `ref` if both are provided.

**Resolution order:**

1. If `sha` is provided, fork at that exact commit
2. If `ref` is provided, fork at the tip of that branch/tag
3. Otherwise, fork at the source repository's HEAD

The fork inherits the source repository's default branch. Set `defaultBranch` on the request to
override it.

> When `baseRepo` contains `id`, a fork is created from the specified repository. See the
> [Repository Forks guide](https://code.storage/docs/repos/forking.md) for details.

## Response

Returns a `Repository` instance with the following properties:

**id** `string`

The repository identifier

**defaultBranch** `string`

The repository's default branch name (e.g., `main`)

The returned repository instance also provides methods for managing branches, commits, files, and
more. See the other SDK reference pages for details.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.