Skip to content

Git Operations

The Daytona SDK provides built-in Git support through the git module in Workspaces. This guide covers all available Git operations and best practices.

Basic Operations

Daytona SDK provides an option to clone, check status, and manage Git repositories in Workspaces. You can interact with Git repositories using the git module.

Cloning Repositories

Daytona SDK provides an option to clone Git repositories into Workspaces using Python and TypeScript. You can clone public or private repositories, specific branches, and authenticate using personal access tokens.

# Basic clone
workspace.git.clone(
url="https://github.com/user/repo.git",
path="/workspace/repo"
)
# Clone with authentication
workspace.git.clone(
url="<https://github.com/user/repo.git>",
path="/workspace/repo",
username="git",
password="personal_access_token"
)
# Clone specific branch
workspace.git.clone(
url="<https://github.com/user/repo.git>",
path="/workspace/repo",
branch="develop"
)

Repository Status

Daytona SDK provides an option to check the status of Git repositories in Workspaces. You can get the current branch, modified files, number of commits ahead and behind main branch using Python and TypeScript.

# Get repository status
status = workspace.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 branches
response = workspace.git.branches("/workspace/repo")
for branch in response.branches:
print(f"Branch: {branch}")

Branch Operations

Daytona SDK provides an option to manage branches in Git repositories. You can create, switch, and delete branches.

Managing Branches

Daytona SDK provides an option to create, switch, and delete branches in Git repositories using Python and TypeScript.

# Create new branch
workspace.git.create_branch("/workspace/repo", "feature/new-feature")
# Switch branch
workspace.git.checkout("/workspace/repo", "feature/new-feature")
# Delete branch
workspace.git.delete_branch("/workspace/repo", "feature/old-feature")

Staging and Committing

Daytona SDK provides an option to stage and commit changes in Git repositories. You can stage specific files, all changes, and commit with a message using Python and TypeScript.

Working with Changes

# Stage specific files
workspace.git.add("/workspace/repo", ["file1.txt", "file2.txt"])
# Stage all changes
workspace.git.add("/workspace/repo", ["."])
# Commit changes
workspace.git.commit("/workspace/repo", "feat: add new feature")
# Get commit history
commits = workspace.git.log("/workspace/repo")
for commit in commits:
print(f"Commit: {commit.hash}")
print(f"Author: {commit.author}")
print(f"Message: {commit.message}")

Remote Operations

Daytona SDK provides an option to work with remote repositories in Git. You can push changes, pull changes, and list remotes.

Working with Remotes

Daytona SDK provides an option to push, pull, and list remotes in Git repositories using Python and TypeScript.

# Push changes
workspace.git.push("/workspace/repo")
# Pull changes
workspace.git.pull("/workspace/repo")
# List remotes
remotes = workspace.git.list_remotes("/workspace/repo")
for remote in remotes:
print(f"Remote: {remote.name} URL: {remote.url}")