DaytonaDocs

Git

Git operations inside the sandbox.

Git performs git operations on repositories inside a sandbox. Obtain it as sandbox.git. Every method takes the repository's in-sandbox path as its first argument. For private repositories, clone/push/pull accept username/password (use a personal access token as the password). See the git guide.

clone()

Clones a repository into the sandbox, optionally at a specific branch or commit, and optionally with credentials for private repos.

TypeScript
clone(
  url: string,
  path: string,
  branch?: string,
  commitId?: string,
  username?: string,
  password?: string,
): Promise<void>
ParameterTypeDefaultDescription
urlstringRepository URL.
pathstringIn-sandbox destination directory.
branchstringBranch to check out.
commitIdstringSpecific commit to check out.
usernamestringUsername for private repos.
passwordstringPassword or access token.
TypeScript
await sandbox.git.clone('https://github.com/acme/app.git', '/workspace/app', 'main')

status()

Returns the working-tree status of a repository: current branch, ahead/behind counts, and per-file staging/worktree state.

TypeScript
status(path: string): Promise<GitStatus>

Returns: GitStatus{ currentBranch, ahead?, behind?, branchPublished?, fileStatus? }.

branches()

Lists the branches of a repository.

TypeScript
branches(path: string): Promise<ListBranchResponse>

Returns: { branches: string[] }.

createBranch()

Creates a new branch.

TypeScript
createBranch(path: string, name: string): Promise<void>

deleteBranch()

Deletes a branch.

TypeScript
deleteBranch(path: string, name: string): Promise<void>

checkoutBranch()

Checks out an existing branch.

TypeScript
checkoutBranch(path: string, branch: string): Promise<void>

add()

Stages files for the next commit. Paths in files are relative to the repository root.

TypeScript
add(path: string, files: string[]): Promise<void>
TypeScript
await sandbox.git.add('/workspace/app', ['src/main.ts', 'README.md'])

commit()

Commits staged changes with the given message and author identity.

TypeScript
commit(path: string, message: string, author: string, email: string): Promise<GitCommitResponse>
ParameterTypeDefaultDescription
pathstringRepository path.
messagestringCommit message.
authorstringAuthor name.
emailstringAuthor email.

Returns: { hash: string }.

TypeScript
const { hash } = await sandbox.git.commit('/workspace/app', 'Fix build', 'CI Bot', 'ci@example.com')

push()

Pushes commits to the remote. Provide username/password for private remotes.

TypeScript
push(path: string, username?: string, password?: string): Promise<void>

pull()

Pulls from the remote. Provide username/password for private remotes.

TypeScript
pull(path: string, username?: string, password?: string): Promise<void>

On this page