Daytona SDKは、Sandbox内の`git`モジュールを通じてGitの組み込みサポートを提供します。本ガイドでは、利用可能なすべてのGit操作とベストプラクティスを解説します。

## 基本操作

Daytona SDKは、Sandbox（Daytonaが管理する隔離された一時的な実行環境）内でGitリポジトリのクローン、ステータス確認、管理を行う機能を提供します。`git`モジュールを使ってGitリポジトリを操作できます。

ファイル操作と同様に、クローンの基準ディレクトリは現在のSandboxユーザーのホームです。例えば、`workspace/repo` は `/home/[username]/workspace/repo` を意味します。先頭を `/` にすることで作業ディレクトリに絶対パスも指定できます。

### リポジトリのクローン

Daytona SDKは、PythonおよびTypeScriptからSandboxにGitリポジトリをクローンできます。パブリック/プライベートリポジトリ、特定ブランチのクローンに対応し、Personal Access Tokenを用いた認証も可能です。

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

### リポジトリのステータス

Daytona SDKは、Sandbox内のGitリポジトリのステータス確認にも対応しています。PythonおよびTypeScriptで、現在のブランチ、変更ファイル、メインブランチに対する先行/遅行コミット数を取得できます。

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

## ブランチ操作

Daytona SDK は、Git リポジトリのブランチ管理機能を提供します。ブランチの作成・切り替え・削除が可能です。

### ブランチの管理

Daytona SDK では、Python と TypeScript から Git リポジトリのブランチを作成・切り替え・削除できます。

<Tabs>
<Tabs.Item title="Python" icon="python">
```python
# 新しいブランチを作成
sandbox.git.create_branch("workspace/repo", "feature/new-feature")

# ブランチを切り替え
sandbox.git.checkout_branch("workspace/repo", "feature/new-feature")

# ブランチを削除
sandbox.git.delete_branch("workspace/repo", "feature/old-feature")

```
</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">
```typescript
// 新しいブランチを作成
await sandbox.git.createBranch("workspace/repo", "feature/new-feature");

// ブランチを切り替え
await sandbox.git.checkoutBranch("workspace/repo", "feature/new-feature");

// ブランチを削除
await sandbox.git.deleteBranch("workspace/repo", "feature/old-feature");
```

</Tabs.Item>
</Tabs>

## ステージングとコミット

Daytona SDK では、Git リポジトリの変更をステージしてコミットできます。Python と TypeScript から、特定のファイルのみ、またはすべての変更をステージし、メッセージ付きでコミットできます。

### 変更の扱い

<Tabs>
<Tabs.Item title="Python" icon="python">
```python
# 特定のファイルをステージ
sandbox.git.add("workspace/repo", ["file1.txt", "file2.txt"])

# すべての変更をステージ
sandbox.git.add("workspace/repo", ["."])

# 変更をコミット
sandbox.git.commit("workspace/repo", "feat: add new feature", "John Doe", "john@example.com")
```
</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">
```typescript
// 特定のファイルをステージ
await sandbox.git.add("workspace/repo", ["file1.txt", "file2.txt"]);

// すべての変更をステージ
await sandbox.git.add("workspace/repo", ["."]);

// 変更をコミット
await sandbox.git.commit("workspace/repo", "feat: add new feature", "John Doe", "john@example.com");
```

</Tabs.Item>
</Tabs>

## リモート操作

Daytona SDK は Git のリモートリポジトリを扱う機能を提供します。変更のプッシュ、変更のプル、リモートの一覧表示が可能です。

### リモートの操作

Daytona SDK は、Python と TypeScript から Git リポジトリに対してプッシュ、プル、リモートの一覧表示を行う機能を提供します。

<Tabs>
<Tabs.Item title="Python" icon="python">
```python
# 変更をプッシュ
sandbox.git.push("workspace/repo")

# 変更をプル
sandbox.git.pull("workspace/repo")

```
</Tabs.Item>
<Tabs.Item title="TypeScript" icon="typescript">
```typescript
// 変更をプッシュ
await sandbox.git.push("workspace/repo");

// 変更をプル
await sandbox.git.pull("workspace/repo");
```

</Tabs.Item>
</Tabs>