# Git integration: branch picker \+ worktrees · PR \#3 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/3)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: merged

Source repository: pingdotgg/t3code

Source branch: juliusmarminge/git-integration

Target branch: main

Head commit: 94420192359d68c03241f03f47cf8d670abafa15

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/3)

[Commits](https://git.cafe/pingdotgg/t3code/pull/3/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/3/diffs?format=markdown)

## Description

---

Closes #7 (Does not implement multiple threads per worktree)

## Summary

Users can now right-click on "+ New thread" to create threads from specific git branches, with optional worktree creation for isolated agent work.

## Features

- Branch context menu showing local branches sorted by current/default/alphabetical
- Option to create git worktree for each branch before starting a thread
- Graceful handling of non-git repositories with "Initialize git repo" button
- Thread model extended with branch/worktreePath fields for persistence
- Agent sessions use worktree path as cwd when available
- Updated persistence schema to store branch and worktree info

## Test Plan

- Right-click "+ New thread" on a git-tracked project to see branch list
- Select a branch to create thread with that branch in metadata
- Click "worktree" button to create isolated worktree before starting thread
- On non-git project, click to see "Not a git repository" with init option
- Verify agent runs in worktree cwd when applicable
- Verify branch/worktree badge displays in chat header

🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/pingdotgg/codething-mvp/pull/3" target="_blank">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
    <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin">
  </picture>
</a>
<!-- devin-review-badge-end -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Branch toolbar beneath chat input to choose branch and environment (Local vs Worktree); environment locks after the first message.
  * Branch picker auto-populates from the repository; toolbar hidden for non-git projects.
  * First message in Worktree mode can create a new worktree and associate it with the thread; branch/worktree badges appear in header and sidebar.

* **Tests**
  * Extensive unit and integration tests for branch, worktree, checkout, and end-to-end git flows.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
