apps/docs/src/content/docs/en/ruby-sdk/git.mdx
Main class for a new Git handler instance.
def initialize(sandbox_id:, toolbox_api:, otel_state:)
Initializes a new Git handler instance.
Parameters:
sandbox_id String - The Sandbox ID.toolbox_api DaytonaToolboxApiClient:GitApi - API client for Sandbox operations.otel_state Daytona:OtelState, nil -Returns:
Git - a new instance of Gitdef sandbox_id()
Returns:
String - The Sandbox IDdef toolbox_api()
Returns:
DaytonaToolboxApiClient:GitApi - API client for Sandbox operationsdef add(path, files)
Stages the specified files for the next commit, similar to running 'git add' on the command line.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.files Array<String> - List of file paths or directories to stage, relative to the repository root.Returns:
voidRaises:
Daytona:Sdk:Error - if adding files failsExamples:
# Stage a single file
sandbox.git.add("workspace/repo", ["file.txt"])
# Stage multiple files
sandbox.git.add("workspace/repo", [
"src/main.rb",
"spec/main_spec.rb",
"README.md"
])
def branches(path)
Lists branches in the repository.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.Returns:
DaytonaApiClient:ListBranchResponse - List of branches in the repository.Raises:
Daytona:Sdk:Error - if listing branches failsExamples:
response = sandbox.git.branches("workspace/repo")
puts "Branches: #{response.branches}"
def clone(url:, path:, branch:, commit_id:, username:, password:)
Clones a Git repository into the specified path. It supports cloning specific branches or commits, and can authenticate with the remote repository if credentials are provided.
Parameters:
url String - Repository URL to clone from.path String - Path where the repository should be cloned. Relative paths are resolved
based on the sandbox working directory.branch String, nil - Specific branch to clone. If not specified,
clones the default branch.commit_id String, nil - Specific commit to clone. If specified,
the repository will be left in a detached HEAD state at this commit.username String, nil - Git username for authentication.password String, nil - Git password or token for authentication.Returns:
voidRaises:
Daytona:Sdk:Error - if cloning repository failsExamples:
# Clone the default branch
sandbox.git.clone(
url: "https://github.com/user/repo.git",
path: "workspace/repo"
)
# Clone a specific branch with authentication
sandbox.git.clone(
url: "https://github.com/user/private-repo.git",
path: "workspace/private",
branch: "develop",
username: "user",
password: "token"
)
# Clone a specific commit
sandbox.git.clone(
url: "https://github.com/user/repo.git",
path: "workspace/repo-old",
commit_id: "abc123"
)
def commit(path:, message:, author:, email:, allow_empty:)
Creates a new commit with the staged changes. Make sure to stage changes using the add() method before committing.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.message String - Commit message describing the changes.author String - Name of the commit author.email String - Email address of the commit author.allow_empty Boolean - Allow creating an empty commit when no changes are staged. Defaults to false.Returns:
GitCommitResponse - Response containing the commit SHA.Raises:
Daytona:Sdk:Error - if committing changes failsExamples:
# Stage and commit changes
sandbox.git.add("workspace/repo", ["README.md"])
commit_response = sandbox.git.commit(
path: "workspace/repo",
message: "Update documentation",
author: "John Doe",
email: "[email protected]",
allow_empty: true
)
puts "Commit SHA: #{commit_response.sha}"
def push(path:, username:, password:)
Pushes all local commits on the current branch to the remote repository. If the remote repository requires authentication, provide username and password/token.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.username String, nil - Git username for authentication.password String, nil - Git password or token for authentication.Returns:
voidRaises:
Daytona:Sdk:Error - if pushing changes failsExamples:
# Push without authentication (for public repos or SSH)
sandbox.git.push("workspace/repo")
# Push with authentication
sandbox.git.push(
path: "workspace/repo",
username: "user",
password: "github_token"
)
def pull(path:, username:, password:)
Pulls changes from the remote repository. If the remote repository requires authentication, provide username and password/token.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.username String, nil - Git username for authentication.password String, nil - Git password or token for authentication.Returns:
voidRaises:
Daytona:Sdk:Error - if pulling changes failsExamples:
# Pull without authentication
sandbox.git.pull("workspace/repo")
# Pull with authentication
sandbox.git.pull(
path: "workspace/repo",
username: "user",
password: "github_token"
)
def status(path)
Gets the current Git repository status.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.Returns:
DaytonaToolboxApiClient:GitStatus - Repository status information including:Raises:
Daytona:Sdk:Error - if getting status failsExamples:
status = sandbox.git.status("workspace/repo")
puts "On branch: #{status.current_branch}"
puts "Commits ahead: #{status.ahead}"
puts "Commits behind: #{status.behind}"
def checkout_branch(path, branch)
Checkout branch in the repository.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.branch String - Name of the branch to checkoutReturns:
voidRaises:
Daytona:Sdk:Error - if checking out branch failsExamples:
# Checkout a branch
sandbox.git.checkout_branch("workspace/repo", "feature-branch")
def create_branch(path, name)
Create branch in the repository.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.name String - Name of the new branch to createReturns:
voidRaises:
Daytona:Sdk:Error - if creating branch failsExamples:
# Create a new branch
sandbox.git.create_branch("workspace/repo", "new-feature")
def delete_branch(path, name)
Delete branch in the repository.
Parameters:
path String - Path to the Git repository root. Relative paths are resolved based on
the sandbox working directory.name String - Name of the branch to deleteReturns:
voidRaises:
Daytona:Sdk:Error - if deleting branch failsExamples:
# Delete a branch
sandbox.git.delete_branch("workspace/repo", "old-feature")