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

## Create An Empty Repository

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

const { repo } = await freestyle.git.repos.create();
```


## 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",
  },
});
```


## Import Files

Import a set of files without preserving external Git history:

```ts
await freestyle.git.repos.create({
  import: {
    type: "files",
    commitMessage: "initial import",
    files: {
      "README.md": {
        content: "# Hello World\n",
      },
    },
  },
});
```

You can also import from Git, tar, or zip sources:

```ts
await freestyle.git.repos.create({
  import: {
    type: "git",
    commitMessage: "import from git",
    url: "https://github.com/user/repo.git",
  },
});

await freestyle.git.repos.create({
  import: {
    type: "tar",
    commitMessage: "import from tar",
    url: "https://example.com/files.tar.gz",
  },
});

await freestyle.git.repos.create({
  import: {
    type: "zip",
    commitMessage: "import from zip",
    url: "https://example.com/files.zip",
  },
});
```


## List Repositories

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

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


## 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.
