LogoFreestyle

Managing Repositories

Create, list, and delete Git repositories on Freestyle.

Managing Repositories

Creating a Repository

Create a basic empty repository:

import { FreestyleSandboxes } from "freestyle-sandboxes";

const sandboxes = new FreestyleSandboxes({
  apiKey: "your-api-key",
});

sandboxes
  .createGitRepository({
    name: "example-repo",
  })
  .then((res) => {
    console.log(res.repoId);
  });

The repository name is optional and for display purposes only. Freestyle generates the actual repository ID.

Create a public repository:

sandboxes
  .createGitRepository({
    name: "public-example",
    public: true,
  })
  .then((res) => {
    console.log(res.repoId);
  });

Forking from External Sources

Clone an existing Git repository:

sandboxes.createGitRepository({
  name: 'forked-repo',
  source: {
    url: 'https://github.com/freestyle-sh/cloudstate',
    branch: 'main', // Optional: defaults to repository's default branch
    depth: 1, // Optional: shallow clone depth
  }
}).then(res => {
  console.log(res.repoId);
});

Importing Static Content

Import static assets or files with an initial commit. You can import from files, tar archives, zip archives, or Git repositories.

Import from Files

sandboxes.createGitRepository({
  name: 'imported-files',
  import: {
    type: 'files',
    files: {
      'index.html': '<html><body>Hello World</body></html>',
      'styles.css': 'body { margin: 0; }',
      'app/main.js': 'console.log("Hello");'
    },
    commitMessage: 'Initial commit',
    authorName: 'Your Name', // Optional
    authorEmail: 'you@example.com', // Optional
  }
}).then(res => {
  console.log(res.repoId);
});

Import from Tar Archive

sandboxes.createGitRepository({
  name: 'imported-tar',
  import: {
    type: 'tar',
    url: 'https://example.com/archive.tar.gz',
    dir: 'subdirectory', // Optional: extract specific directory
    commitMessage: 'Import from tar archive',
    authorName: 'Your Name', // Optional
    authorEmail: 'you@example.com', // Optional
  }
}).then(res => {
  console.log(res.repoId);
});

Import from Zip Archive

sandboxes.createGitRepository({
  name: 'imported-zip',
  import: {
    type: 'zip',
    url: 'https://example.com/archive.zip',
    dir: 'subdirectory', // Optional: extract specific directory
    commitMessage: 'Import from zip archive',
    authorName: 'Your Name', // Optional
    authorEmail: 'you@example.com', // Optional
  }
}).then(res => {
  console.log(res.repoId);
});

Import from Git Repository

Import creates a new initial commit rather than cloning history:

sandboxes.createGitRepository({
  name: 'imported-git',
  import: {
    type: 'git',
    url: 'https://github.com/example/repo',
    branch: 'main', // Optional
    dir: 'src', // Optional: import specific directory
    commitMessage: 'Import from Git repository',
    authorName: 'Your Name', // Optional
    authorEmail: 'you@example.com', // Optional
  }
}).then(res => {
  console.log(res.repoId);
});

You cannot use both source and import when creating a repository - they are mutually exclusive. Use source to fork with full history, or import to create a new repository with an initial commit.

Pushing Code

After creating a repository, push code using standard Git commands:

# Add the repository as a remote
git remote add freestyle https://git.freestyle.sh/your-repo-id

# Push your code
git push freestyle main

Listing Repositories

List all repositories in your account:

sandboxes.listGitRepositories().then((repos) => {
  console.log(repos);
});

Deleting Repositories

Delete a repository when no longer needed:

sandboxes
  .deleteGitRepository({
    repoId: "repo-id",
  })
  .then(() => {
    console.log("Repository deleted");
  });

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.