Git Worktrees with git-wt
Use git wt for worktree lifecycle operations. Do not use raw
git worktree add, remove, move, or prune when git-wt can perform the
operation.
Current Worktree Detection
Before creating or switching worktrees, compare these paths:
git rev-parse --path-format=absolute --git-dir
git rev-parse --path-format=absolute --git-common-dir
Different paths mean the current directory is already inside a linked worktree. Continue in that worktree unless the user explicitly requests a different one. Do not create or select another worktree merely to satisfy an isolation convention.
Equal paths mean the current directory is the main worktree. Create or select a linked worktree only when the task or user actually requires isolation.
Workflow
- Detect whether the current directory is already a linked worktree.
- If a lifecycle operation is needed, confirm the command is available with
git-wt --version. - Inspect existing worktrees with
git wt --json | jq. - Create or select a worktree with
git wt --nocd <branch-or-worktree>. Add a start point when needed:git wt --nocd <branch-or-worktree> <start-point>. - Treat the printed path as the worktree root and use it as the working directory for subsequent commands. Do not rely on shell directory changes persisting between tool calls.
- Verify the branch and status inside the selected worktree before editing:
git branch --show-currentandgit status --short.
Use git wt -b <branch> --nocd <worktree> when the worktree directory and
branch names should differ.
Destructive Operations
- Delete safely with
git wt -d <branch-or-worktree>. - Use
git wt -D <branch-or-worktree>only when the user explicitly requests forced deletion or safe deletion fails and discarding the work is confirmed. - Rename safely with
git wt -m [<old>] <new>. - Use
git wt -M [<old>] <new>only when overwrite or force behaviour is explicitly required. - Inspect
git status --shortin the target worktree before deleting or force-renaming it.
Run git-wt --help for flags and configured behaviour when the requested
operation is not covered above.