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.

Python
def clone(
    url: str,
    path: str,
    branch: str | None = None,
    commit_id: str | None = None,
    username: str | None = None,
    password: str | None = None,
) -> None
ParameterTypeDefaultDescription
urlstrRepository URL.
pathstrIn-sandbox destination directory.
branchstrNoneBranch to check out.
commit_idstrNoneSpecific commit to check out.
usernamestrNoneUsername for private repos.
passwordstrNonePassword or access token.
Python
sandbox.git.clone("https://github.com/acme/app.git", "/workspace/app", branch="main")

status()

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

Python
def status(path: str) -> Dict[str, Any]

branches()

Lists the branches of a repository.

Python
def branches(path: str) -> Dict[str, Any]

Returns: a dict with a branches list.

create_branch()

Creates a new branch.

Python
def create_branch(path: str, name: str) -> None

delete_branch()

Deletes a branch.

Python
def delete_branch(path: str, name: str) -> None

checkout_branch()

Checks out an existing branch.

Python
def checkout_branch(path: str, branch: str) -> None

add()

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

Python
def add(path: str, files: List[str]) -> None
Python
sandbox.git.add("/workspace/app", ["src/main.py", "README.md"])

commit()

Commits staged changes with the given message and author identity.

Python
def commit(path: str, message: str, author: str, email: str) -> Dict[str, Any]
ParameterTypeDefaultDescription
pathstrRepository path.
messagestrCommit message.
authorstrAuthor name.
emailstrAuthor email.

Returns: a dict with the commit hash.

Python
result = sandbox.git.commit("/workspace/app", "Fix build", "CI Bot", "ci@example.com")
print(result["hash"])

push()

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

Python
def push(path: str, username: str | None = None, password: str | None = None) -> None

pull()

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

Python
def pull(path: str, username: str | None = None, password: str | None = None) -> None

On this page