---
title: "Repositories"
description: "Create, list, delete, and authenticate Freestyle Git repositories."
url: "/docs/git/repositories"
---

## Create An Empty Repository

```ts
import { freestyle } from "freestyle";

const { repoId, repo } = await freestyle.git.repos.create({
  name: "my-repo",
});
```


## Create From A Source Repository

Fork an existing repository and preserve its history:

```ts
await freestyle.git.repos.create({
  source: {
    url: "https://github.com/user/repo.git",
    rev: "main",
  },
});
```


## List Repositories

```ts
const result = await freestyle.git.repos.list({
  limit: 20,
  cursor: "0",
});

for (const repo of result.repositories) {
  console.log(repo);
}
```


## Delete A Repository

```ts
await freestyle.git.repos.delete({
  repoId: "your-repo-id",
});
```

Deleting a repository permanently removes its Git data.


## Authenticate Native Git

Repositories are private by default. Grant access through Freestyle identities.

```ts
const { identity } = await freestyle.identities.create();

await identity.permissions.git.grant({
  permission: "write",
  repoId,
});

const { token } = await identity.tokens.create();

console.log(
  `git clone https://x-access-token:${token}@git.freestyle.sh/${repoId}`,
);
```

For local testing with your API key:

```bash
git -c http.extraHeader="Authorization: Bearer $FREESTYLE_API_KEY" \
  clone https://git.freestyle.sh/<repo-id>
```


## Public Repositories

```ts
await freestyle.git.repos.create({
  public: true,
});
```

Public repositories can be cloned without authentication, but pushes still require write access.
