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-keynpm i freestyle-sandboxes@betaCreating 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,
});