Git worktrees - Lesson 1 of 5
Inspect before you touch
A worktree is another working directory attached to one Git repository. Before you edit, remove, or integrate it, establish exactly what is checked out and what has changed.
The model
Git keeps one main worktree and can attach zero or more linked worktrees. Linked worktrees share repository objects and most refs, while each has its own files, index, and HEAD. A commit made in one is immediately known to the others; an uncommitted edit is not.
Guardrail: Git normally refuses to check the same branch out in two worktrees. That is a useful safeguard, not friction to bypass.
The inspection loop
Listpaths and branchesEnterthe chosen pathStatustracked and untracked workDiffwhat changedHistorywhat was committedDecidekeep, integrate, or remove
git worktree list --verbose
cd ../task-path
git status --short
git branch --show-current
git diff
git diff --cached
git log --oneline --decorate -5
Run it in that order. The branch name alone does not tell you whether valuable work is untracked, staged, or already committed.
Read the result
| You find | Meaning | Next move |
|---|---|---|
| Clean status, useful commits | Work is preserved by branch history. | Inspect the commit range before integration. |
| Dirty status | Useful work may exist only in this directory. | Review and commit, patch, or intentionally discard it. |
| Detached HEAD | The worktree is not on a branch. | Create a branch before making durable changes. |
| Prunable marker | Git cannot find the recorded directory. | Use the recovery lesson; do not guess with force. |
Retrieval check
Primary reading
- git-worktree - read Description, Commands, and Refs.
Ask follow-up questions: Bring a real
git worktree list --verbose output to the agent before deleting or moving a worktree you did not create.