Git Worktrees | LanMate User Guide
Using the Qianxin edition of LanMate?View Qianxin Edition User Guide

Git Worktrees

Worktrees let different tasks run in mutually isolated Git environments. When you need to handle multiple tasks in the same project in parallel—developing a new feature while fixing an urgent bug, for example—without the two sets of changes stepping on each other, worktrees are the answer.

Each worktree is an independent directory with its own files, branch, and code changes. Your main working directory stays clean and untouched; when the task is done, you merge the results back.

Terminology

Term Description
Worktree A native Git mechanism that lets one repository have multiple independent working directories, each checking out a different branch
Worktree branch The branch currently checked out in a worktree, named like lanmate/task-8c295571
Worktree directory The local folder for a worktree. LanMate keeps them under the managed root ~/.lanmate/worktrees/<project>/
Base branch The branch the worktree was created from; changes eventually merge back into it

Worktrees are never created inside your project repository (nothing extra shows up in git status). They live in LanMate’s own directory instead, grouped by project and managed centrally.

Scope and Prerequisites

Non-Git projects or office tasks that don’t touch code run directly in the project’s current directory—no worktree needed.

Four Worktree Sources

Source When created Naming
Task You pick “New worktree” in the composer and send the task task-<session8>
Fork You choose “Continue in a new worktree” when forking a session fork-<session8>
Subagent A coding task’s subagent needs an isolated environment subagent-<agent8>
Task board A board task is dispatched to an Agent taskboard-<task>

All four kinds appear in Settings → Git → Worktrees, tagged by source, ready to clean up.

Create a Worktree for a New Task

  1. In a Git project, find the Git workspace selector below the chat input
  2. It defaults to “Local” (the project’s current worktree); switch to “New worktree”
  3. Optional: pick a base branch (defaults to the current branch)
  4. Send the task; LanMate creates the dedicated worktree automatically

Once the task starts, the pinned summary at the top of the session shows the worktree branch, confirming that change isolation is in effect.

Continue in a New Worktree

When a conversation reaches a point where you want to try another path without polluting the original working area:

  1. Hover the target message and click “Fork”
  2. Git projects offer a choice: New chat (same directory) or Continue in a new worktree
  3. Choosing the worktree carries over the source checkout’s uncommitted state (including untracked files), so in-flight changes are never lost

See Session Management for details.

AI Merge

When the task is done and the changes check out, merge the worktree’s results back into the base branch:

  1. Open the pinned summary at the top of the session and expand Git status
  2. Click “AI Merge” on the worktree row
  3. The agent first reviews the worktree’s changes, commits any uncommitted work following the project’s conventions, then merges back into the base branch; conflicts are resolved per repository convention

The merge is a complete Git workflow executed by the agent—transparent and auditable. If you have special requirements for the merge strategy, just say so in the chat.

Check Disk Usage

Worktrees are full checkouts and consume disk space. Check anytime:

  1. Go to Settings → Git → Worktrees
  2. The “Worktree disk usage” section lists every worktree’s size, branch, and last-used time, grouped by source

When a project’s total worktree usage reaches the threshold you configured, a reminder bar appears above the input with a shortcut to cleanup.

Clean Up Worktrees

Cleanup deletes the worktree directory to free disk space; conversation history and code change records are kept. You can check “Keep branch”—only the directory is deleted, the branch stays, and the changes remain recoverable from it later.

Entry: Settings → Git → Worktrees → select the target worktrees → Clean up selected.

Subagent worktrees have snapshot protection: before cleanup, uncommitted changes are saved to a lanmate/subagent-* snapshot branch—delete the directory and the output is still recoverable from the branch.

Setting Location Description
Keep branch by default when cleaning Settings → Git → Worktrees When on, the cleanup confirmation defaults to “Keep branch”
Disk usage alert (GB) Settings → Git → Worktrees Reminds above the input when total usage reaches the threshold; set 0 to disable