Daytona provides built-in Git support through the git module in sandboxes.
Basic operations
Daytona provides methods to clone, check status, and manage Git repositories in sandboxes.
Similar to file system operations, the starting cloning directory is the current sandbox working directory. It uses the WORKDIR specified in the Dockerfile if present, or falls back to the user’s home directory if not - e.g. workspace/repo implies /my-work-dir/workspace/repo, but you are free to provide an absolute workDir path as well (by starting the path with /).
Clone repositories
Daytona provides methods to clone Git repositories into sandboxes. You can clone public or private repositories, specific branches, and authenticate using personal access tokens.
Python
TypeScript
Ruby
Go
API
Copy
# Basic clonesandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo")# Clone with authenticationsandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo", username="git", password="personal_access_token")# Clone specific branchsandbox.git.clone( url="https://github.com/user/repo.git", path="workspace/repo", branch="develop")
Daytona provides methods to check the status of Git repositories in sandboxes. You can get the current branch, modified files, number of commits ahead and behind main branch.
Python
TypeScript
Ruby
Go
API
Copy
# Get repository statusstatus = sandbox.git.status("workspace/repo")print(f"Current branch: {status.current_branch}")print(f"Commits ahead: {status.ahead}")print(f"Commits behind: {status.behind}")for file in status.file_status: print(f"File: {file.name}")# List branchesresponse = sandbox.git.branches("workspace/repo")for branch in response.branches: print(f"Branch: {branch}")
Copy
// Get repository statusconst status = await sandbox.git.status("workspace/repo");console.log(`Current branch: ${status.currentBranch}`);console.log(`Commits ahead: ${status.ahead}`);console.log(`Commits behind: ${status.behind}`);status.fileStatus.forEach(file => { console.log(`File: ${file.name}`);});// List branchesconst response = await sandbox.git.branches("workspace/repo");response.branches.forEach(branch => { console.log(`Branch: ${branch}`);});
Copy
# Get repository statusstatus = sandbox.git.status('workspace/repo')puts "Current branch: #{status.current_branch}"puts "Commits ahead: #{status.ahead}"puts "Commits behind: #{status.behind}"status.file_status.each do |file| puts "File: #{file.name}"end# List branchesresponse = sandbox.git.branches('workspace/repo')response.branches.each do |branch| puts "Branch: #{branch}"end
Daytona provides methods to stage changes in Git repositories. You can stage specific files, all changes, and commit with a message. The following snippet stages the file file.txt and the src directory.
Python
TypeScript
Ruby
Go
API
Copy
# Stage a single filesandbox.git.add("workspace/repo", ["file.txt"])# Stage multiple filessandbox.git.add("workspace/repo", [ "src/main.py", "tests/test_main.py", "README.md"])
Copy
// Stage a single fileawait git.add('workspace/repo', ['file.txt']);// Stage whole repositoryawait git.add('workspace/repo', ['.']);
Copy
# Stage a single filesandbox.git.add('workspace/repo', ['file.txt'])
Daytona provides methods to commit changes in Git repositories. You can commit with a message, author, and email. The following snippet commits the changes with the message Update documentation and the author John Doe and email john@example.com.
Daytona provides methods to work with remote repositories in Git. You can push and pull changes from remote repositories.
Push changes
Daytona provides methods to push changes to remote repositories. The following snippet pushes the changes to a public repository.
Python
TypeScript
Ruby
Go
API
Copy
# Push without authentication (for public repos or SSH)sandbox.git.push("workspace/repo")# Push with authenticationsandbox.git.push( path="workspace/repo", username="user", password="github_token")
Copy
// Push to a public repositoryawait git.push('workspace/repo');// Push to a private repositoryawait git.push( 'workspace/repo', 'user', 'token');
Copy
# Push changessandbox.git.push('workspace/repo')
Copy
// Push without authentication (for public repos or SSH)err := sandbox.Git.Push(ctx, "workspace/repo")if err != nil { log.Fatal(err)}// Push with authenticationerr = sandbox.Git.Push(ctx, "workspace/repo", options.WithPushUsername("user"), options.WithPushPassword("github_token"),)if err != nil { log.Fatal(err)}
Daytona provides methods to pull changes from remote repositories. The following snippet pulls the changes from a public repository.
Python
TypeScript
Ruby
Go
API
Copy
# Pull without authenticationsandbox.git.pull("workspace/repo")# Pull with authenticationsandbox.git.pull( path="workspace/repo", username="user", password="github_token")
Copy
// Pull from a public repositoryawait git.pull('workspace/repo');// Pull from a private repositoryawait git.pull( 'workspace/repo', 'user', 'token');