LogoFreestyle

Getting Started with Git

Sign up at admin.freestyle.sh, create an api key, and configure it in your environment.

FREESTYLE_API_KEY=your-api-key
npm i freestyle-sandboxes@beta

Creating a Git Repository

Calling create in the git.repos namespace will create a new empty git repository.

import { freestyle } from "freestyle-sandboxes";

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

You can also source an existing repository and all it's history by providing the URL and branch.

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

Or you can import a repository's files directly without any history. Raw files, tar urls, and zip urls are also supported types under import.

await freestyle.git.repos.create({
    import: {
        type: "git",
        url: "https://github.com/user/repo.git",
    },
});
await freestyle.git.repos.create({
    import: {
        type: "files",
        files: {
            "README.md": {
                content: "# Hello World\nThis is my repo.",
            },
        },
    },
});
await freestyle.git.repos.create({
    import: {
        type: "tar",
        url: "https://example.com/files.tar.gz",
    },
});
await freestyle.git.repos.create({
    import: {
        type: "zip",
        url: "https://example.com/files.zip",
    },
});

Pulling and Authentication

By default git repositories are private so to clone one, so you'll need to create a freestyle identity and access token.

const { identity } = await freestyle.identities.create();
await identity.permissions.git.create({
  permission: "write",
  repoId: repoId,
});
const { token } = await identity.createToken();

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

You can also use bearer auth and your freestyle api key to clone a repository. This is mostly useful for testing.

git -c http.extraHeader "Authorization: Bearer <your-api-key>" clone https://git.freestyle.sh/<repo-id>

Public repositories can be cloned without authentication, but you'll still need authentication to push changes.

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

On this page

Freestyle AI

Documentation assistant

Experimental: AI responses may not always be accurate—please verify important details with the official documentation.

How can I help?

Ask me about Freestyle while you browse the docs.