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](/docs/en/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.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Basic clone
sandbox.git.clone(
    url="https://github.com/user/repo.git",
    path="workspace/repo"
)

# Clone with authentication
sandbox.git.clone(
    url="https://github.com/user/repo.git",
    path="workspace/repo",
    username="git",
    password="personal_access_token"
)

# Clone specific branch
sandbox.git.clone(
    url="https://github.com/user/repo.git",
    path="workspace/repo",
    branch="develop"
)
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Basic clone
await sandbox.git.clone(
    "https://github.com/user/repo.git",
    "workspace/repo"
);

// Clone with authentication
await sandbox.git.clone(
    "https://github.com/user/repo.git",
    "workspace/repo",
    undefined,
    undefined,
    "git",
    "personal_access_token"
);

// Clone specific branch
await sandbox.git.clone(
    "https://github.com/user/repo.git",
    "workspace/repo",
    "develop"
);
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Basic clone
sandbox.git.clone(
  url: 'https://github.com/user/repo.git',
  path: 'workspace/repo'
)

# Clone with authentication
sandbox.git.clone(
  url: 'https://github.com/user/repo.git',
  path: 'workspace/repo',
  username: 'git',
  password: 'personal_access_token'
)

# Clone specific branch
sandbox.git.clone(
  url: 'https://github.com/user/repo.git',
  path: 'workspace/repo',
  branch: 'develop'
)
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Basic clone
err := sandbox.Git.Clone(ctx, "https://github.com/user/repo.git", "workspace/repo")
if err != nil {
	log.Fatal(err)
}

// Clone with authentication
err = sandbox.Git.Clone(ctx, "https://github.com/user/repo.git", "workspace/repo",
	options.WithUsername("git"),
	options.WithPassword("personal_access_token"),
)
if err != nil {
	log.Fatal(err)
}

// Clone specific branch
err = sandbox.Git.Clone(ctx, "https://github.com/user/repo.git", "workspace/repo",
	options.WithBranch("develop"),
)
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/clone' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "branch": "",
  "commit_id": "",
  "password": "",
  "path": "",
  "url": "",
  "username": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**clone (Python SDK)**](/docs/en/python-sdk/sync/git#gitclone)
>
> [**clone (TypeScript SDK)**](/docs/en/typescript-sdk/git#clone)
>
> [**clone (Ruby SDK)**](/docs/en/ruby-sdk/git#clone)
>
> [**Clone (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Clone)
>
> [**clone repository (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/clone)

### Get repository status

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.

<Tabs>
<Tabs.Item title="Python" icon="python">

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

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Get repository status
const 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 branches
const response = await sandbox.git.branches("workspace/repo");
response.branches.forEach(branch => {
    console.log(`Branch: ${branch}`);
});
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Get repository status
status = 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 branches
response = sandbox.git.branches('workspace/repo')
response.branches.each do |branch|
  puts "Branch: #{branch}"
end
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Get repository status
status, err := sandbox.Git.Status(ctx, "workspace/repo")
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Current branch: %s\n", status.CurrentBranch)
fmt.Printf("Commits ahead: %d\n", status.Ahead)
fmt.Printf("Commits behind: %d\n", status.Behind)
for _, file := range status.FileStatus {
	fmt.Printf("File: %s\n", file.Path)
}

// List branches
branches, err := sandbox.Git.Branches(ctx, "workspace/repo")
if err != nil {
	log.Fatal(err)
}
for _, branch := range branches {
	fmt.Printf("Branch: %s\n", branch)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/status?path='
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**status (Python SDK)**](/docs/en/python-sdk/sync/git#gitstatus)
>
> [**status (TypeScript SDK)**](/docs/en/typescript-sdk/git#status)
>
> [**status (Ruby SDK)**](/docs/en/ruby-sdk/git#status)
>
> [**Status (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Status)
>
> [**get Git repository status (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/GET/git/status)

## Branch operations

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

### Create branches

Daytona provides methods to create branches in Git repositories. The following snippet creates a new branch called `new-feature`.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Create a new branch
sandbox.git.create_branch("workspace/repo", "new-feature")
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Create new branch
await git.createBranch('workspace/repo', 'new-feature');
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Create a new branch
sandbox.git.create_branch('workspace/repo', 'new-feature')
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Create a new branch
err := sandbox.Git.CreateBranch(ctx, "workspace/repo", "new-feature")
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/branches' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "",
  "path": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**create_branch (Python SDK)**](/docs/en/python-sdk/sync/git#gitcreate_branch)
>
> [**createBranch (TypeScript SDK)**](/docs/en/typescript-sdk/git#createbranch)
>
> [**create_branch (Ruby SDK)**](/docs/en/ruby-sdk/git#create_branch)
>
> [**CreateBranch (Go SDK)**](/docs/en/go-sdk/daytona#GitService.CreateBranch)
>
> [**create branch (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/branches)

### Checkout branches

Daytona provides methods to checkout branches in Git repositories. The following snippet checks out the branch called `feature-branch`.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Checkout a branch
sandbox.git.checkout_branch("workspace/repo", "feature-branch")
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Checkout a branch
await git.checkoutBranch('workspace/repo', 'feature-branch');
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Checkout a branch
sandbox.git.checkout_branch('workspace/repo', 'feature-branch')
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Checkout a branch
err := sandbox.Git.Checkout(ctx, "workspace/repo", "feature-branch")
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/checkout' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "branch": "",
  "path": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**checkout_branch (Python SDK)**](/docs/en/python-sdk/sync/git#gitcheckout_branch)
>
> [**checkoutBranch (TypeScript SDK)**](/docs/en/typescript-sdk/git#checkoutbranch)
>
> [**checkout_branch (Ruby SDK)**](/docs/en/ruby-sdk/git#checkout_branch)
>
> [**Checkout (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Checkout)
>
> [**checkout branch (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/checkout)

### Delete branches

Daytona provides methods to delete branches in Git repositories. The following snippet deletes the branch called `old-feature`.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Delete a branch
sandbox.git.delete_branch("workspace/repo", "old-feature")
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Delete a branch
await git.deleteBranch('workspace/repo', 'old-feature');
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Delete a branch
sandbox.git.delete_branch('workspace/repo', 'old-feature')
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Delete a branch
err := sandbox.Git.DeleteBranch(ctx, "workspace/repo", "old-feature")
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/branches' \
  --request DELETE \
  --header 'Content-Type: application/json' \
  --data '{
  "name": "",
  "path": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**delete_branch (Python SDK)**](/docs/en/python-sdk/sync/git#gitdelete_branch)
>
> [**deleteBranch (TypeScript SDK)**](/docs/en/typescript-sdk/git#deletebranch)
>
> [**delete_branch (Ruby SDK)**](/docs/en/ruby-sdk/git#delete_branch)
>
> [**DeleteBranch (Go SDK)**](/docs/en/go-sdk/daytona#GitService.DeleteBranch)
>
> [**delete branch (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/DELETE/git/branches)

## Stage changes

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.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Stage a single file
sandbox.git.add("workspace/repo", ["file.txt"])

# Stage multiple files
sandbox.git.add("workspace/repo", [
    "src/main.py",
    "tests/test_main.py",
    "README.md"
])
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Stage a single file
await git.add('workspace/repo', ['file.txt']);
// Stage whole repository
await git.add('workspace/repo', ['.']);
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Stage a single file
sandbox.git.add('workspace/repo', ['file.txt'])
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Stage a single file
err := sandbox.Git.Add(ctx, "workspace/repo", []string{"file.txt"})
if err != nil {
	log.Fatal(err)
}

// Stage multiple files
err = sandbox.Git.Add(ctx, "workspace/repo", []string{
	"src/main.py",
	"tests/test_main.py",
	"README.md",
})
if err != nil {
	log.Fatal(err)
}

// Stage whole repository
err = sandbox.Git.Add(ctx, "workspace/repo", []string{"."})
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/add' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "files": [
    ""
  ],
  "path": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**add (Python SDK)**](/docs/en/python-sdk/sync/git#gitadd)
>
> [**add (TypeScript SDK)**](/docs/en/typescript-sdk/git#add)
>
> [**add (Ruby SDK)**](/docs/en/ruby-sdk/git#add)
>
> [**Add (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Add)
>
> [**add (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/add)

## Commit changes

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`.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Stage and commit changes
sandbox.git.add("workspace/repo", ["README.md"])
sandbox.git.commit(
    path="workspace/repo",
    message="Update documentation",
    author="John Doe",
    email="john@example.com",
    allow_empty=True
)
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Stage and commit changes
await git.add('workspace/repo', ['README.md']);
await git.commit(
  'workspace/repo',
  'Update documentation',
  'John Doe',
  'john@example.com',
  true
);
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Stage and commit changes
sandbox.git.add('workspace/repo', ['README.md'])
sandbox.git.commit('workspace/repo', 'Update documentation', 'John Doe', 'john@example.com', true)
```

</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Stage and commit changes
err := sandbox.Git.Add(ctx, "workspace/repo", []string{"README.md"})
if err != nil {
	log.Fatal(err)
}

response, err := sandbox.Git.Commit(ctx, "workspace/repo",
	"Update documentation",
	"John Doe",
	"john@example.com",
	options.WithAllowEmpty(true),
)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Commit SHA: %s\n", response.SHA)
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/commit' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "allow_empty": true,
  "author": "",
  "email": "",
  "message": "",
  "path": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**commit (Python SDK)**](/docs/en/python-sdk/sync/git#gitcommit)
>
> [**commit (TypeScript SDK)**](/docs/en/typescript-sdk/git#commit)
>
> [**commit (Ruby SDK)**](/docs/en/ruby-sdk/git#commit)
>
> [**Commit (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Commit)
>
> [**commit (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/commit)

## Remote operations

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.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# 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"
)
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Push to a public repository
await git.push('workspace/repo');

// Push to a private repository
await git.push(
  'workspace/repo',
  'user',
  'token'
);
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">
```ruby
# Push changes
sandbox.git.push('workspace/repo')
```
</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Push without authentication (for public repos or SSH)
err := sandbox.Git.Push(ctx, "workspace/repo")
if err != nil {
	log.Fatal(err)
}

// Push with authentication
err = sandbox.Git.Push(ctx, "workspace/repo",
	options.WithPushUsername("user"),
	options.WithPushPassword("github_token"),
)
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/push' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "password": "",
  "path": "",
  "username": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**push (Python SDK)**](/docs/en/python-sdk/sync/git#gitpush)
>
> [**push (TypeScript SDK)**](/docs/en/typescript-sdk/git#push)
>
> [**push (Ruby SDK)**](/docs/en/ruby-sdk/git#push)
>
> [**Push (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Push)
>
> [**push (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/push)

### Pull changes

Daytona provides methods to pull changes from remote repositories. The following snippet pulls the changes from a public repository.

<Tabs>
<Tabs.Item title="Python" icon="python">

```python
# Pull without authentication
sandbox.git.pull("workspace/repo")

# Pull with authentication
sandbox.git.pull(
    path="workspace/repo",
    username="user",
    password="github_token"
)
```

</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">

```typescript
// Pull from a public repository
await git.pull('workspace/repo');

// Pull from a private repository
await git.pull(
  'workspace/repo',
  'user',
  'token'
);
```

</Tabs.Item>
<Tabs.Item title="Ruby" icon="ruby">

```ruby
# Pull changes
sandbox.git.pull('workspace/repo')
```
</Tabs.Item>
<Tabs.Item title="Go" icon="go">

```go
// Pull without authentication
err := sandbox.Git.Pull(ctx, "workspace/repo")
if err != nil {
	log.Fatal(err)
}

// Pull with authentication
err = sandbox.Git.Pull(ctx, "workspace/repo",
	options.WithPullUsername("user"),
	options.WithPullPassword("github_token"),
)
if err != nil {
	log.Fatal(err)
}
```

</Tabs.Item>
<Tabs.Item title="API" icon="json">

```bash
curl 'https://proxy.app.daytona.io/toolbox/{sandboxId}/git/pull' \
  --request POST \
  --header 'Content-Type: application/json' \
  --data '{
  "password": "",
  "path": "",
  "username": ""
}'
```

</Tabs.Item>
</Tabs>

For more information, see the [Python SDK](/docs/en/python-sdk/sync/git), [TypeScript SDK](/docs/en/typescript-sdk/git), [Ruby SDK](/docs/en/ruby-sdk/git), [Go SDK](/docs/en/go-sdk) and [API](/docs/en/tools/api#daytona-toolbox) references:

> [**pull (Python SDK)**](/docs/en/python-sdk/sync/git#gitpull)
>
> [**pull (TypeScript SDK)**](/docs/en/typescript-sdk/git#pull)
>
> [**pull (Ruby SDK)**](/docs/en/ruby-sdk/git#pull)
>
> [**Pull (Go SDK)**](/docs/en/go-sdk/daytona#GitService.Pull)
>
> [**pull (API)**](/docs/en/tools/api#daytona-toolbox/tag/git/POST/git/pull)
