Create An Empty Repository
import { freestyle } from "freestyle";
const { repo } = await freestyle.git.repos.create();
Create From A Source Repository
Fork an existing repository and preserve its history:
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:
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:
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
const result = await freestyle.git.repos.list({
limit: 20,
cursor: 0,
});
for (const repo of result.repositories) {
console.log(repo.id);
}
Delete A Repository
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.
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:
git -c http.extraHeader="Authorization: Bearer $FREESTYLE_API_KEY" \
clone https://git.freestyle.sh/<repo-id>
Public Repositories
await freestyle.git.repos.create({
public: true,
});
Public repositories can be cloned without authentication, but pushes still require write access.