# Git Integration

Connect GitHub repositories to TeamDay Spaces — clone repos, manage branches, and let agents commit code.

# Git Integration

TeamDay Spaces can be connected to Git repositories. Agents can read code, make changes, commit, and push — all within the sandboxed workspace.

---

## Connect a Repository

### When Creating a Space

```bash
teamday spaces create \
  --name "Backend API" \
  --type git \
  --git-url https://github.com/your-org/your-repo.git
```

Via API:

```bash
curl -X POST "https://cc.teamday.ai/api/v1/spaces" \
  -H "Authorization: Bearer $TEAMDAY_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Backend API",
    "type": "git",
    "gitUrl": "https://github.com/your-org/your-repo.git"
  }'
```

### Authentication

For private repositories, store a GitHub token as a Space secret:

```bash
teamday spaces set-secret <space-id> GITHUB_TOKEN=ghp-your-token
```

The token is used automatically for Git operations.

---

## Git Operations

### Via CLI

```bash
# Check repository status
teamday spaces git <space-id> status

# Pull latest changes
teamday spaces git <space-id> pull
```

### Via Agent (In-Chat)

Agents use the `Bash` tool for Git operations:

```
User: "Pull the latest changes and check for any new commits"

Agent runs:
  git pull origin main
  git log --oneline -10
```

Agents can also commit and push:

```
User: "Fix the typo in README.md and commit it"

Agent runs:
  # Makes the edit using the Edit tool
  git add README.md
  git commit -m "Fix typo in README.md"
  git push
```

### Via Web App

The web app provides a Git panel where you can:
- View file diffs
- Stage and unstage changes
- Write commit messages
- Commit and push

---

## Browse Files

List files in the Space filesystem:

```bash
teamday spaces ls <space-id> /
teamday spaces ls <space-id> /src/
```

Agents can also browse files using the `Glob` and `Read` tools during conversations.

---

## Workflows

### Code Review

1. Create a Space from your repo
2. Add a code reviewer agent
3. Ask: "Review the changes in the last 5 commits"

The agent reads the Git history, examines diffs, and provides a structured review.

### Automated Fixes

1. Agent identifies an issue
2. Makes the fix using `Edit` tool
3. Commits with a descriptive message
4. Pushes the change

### Branch Management

Agents can work with branches:

```
User: "Create a branch called fix/header-styling, fix the CSS, and push it"

Agent runs:
  git checkout -b fix/header-styling
  # Makes edits
  git add .
  git commit -m "Fix header styling alignment"
  git push -u origin fix/header-styling
```

---

## Best Practices

- **Use feature branches** — don't let agents push directly to main
- **Store tokens as secrets** — never hardcode credentials
- **Add CLAUDE.md** — give agents context about the repo structure and coding standards
- **Review before merging** — agents can create PRs, but humans should review

---

## Next Steps

- [Spaces & Workspaces](https://docs.teamday.ai/guides/spaces) — Full Space management guide
- [Space Setup](https://docs.teamday.ai/guides/space-setup) — Development environment recipes
- [CLI Tool](https://docs.teamday.ai/guides/cli-tool) — CLI commands for Git and file operations
