| name | gwt |
| description | Manage git worktrees using a centralized worktrees folder. Use for parallel development,
PR reviews, or isolated work.
|
| author | Somto Odera |
| version | 1.1.0 |
| date | "2026-02-01T00:00:00.000Z" |
Git Worktree Manager (gwt)
Problem
Nested worktree directories cause Next.js Turbopack to detect multiple lockfiles, IDE file watchers to get confused, and build tools to traverse into nested worktrees. Sibling worktrees clutter the code directory.
Solution
Use a centralized worktrees/ folder to keep all worktrees organized and your main code directory clean.
Directory Structure
~/code/
├── my-project/ # main repo
├── other-project/ # another repo
└── worktrees/ # all worktrees live here
├── my-project--feat-auth/
├── my-project--fix-bug/
└── other-project--feat-x/
Naming: {repo-name}--{branch-name} (double dash separator, slashes become dashes)
When to Use
- Reviewing PRs in isolation without switching branches
- Parallel development on multiple features
- Testing changes without affecting main branch state
- Overnight/long-running work that shouldn't block other work
Commands
gwt new <branch> [from]
gwt ls
gwt go <branch>
gwt switch <branch>
gwt rm <branch>
gwt here
gwt path <branch>
Flags
--json - Machine-readable output
--no-env - Skip .env file copying
--keep-branch - Don't delete branch on rm
Environment Variables
GWT_WORKTREE_DIR - Override worktrees directory (default: ../worktrees)
Human Usage
Starting a new session in a worktree
gwt new feat/my-feature
gwt switch my-feature
Quick switching
gwt switch auth
Agent Usage
Working directory limitation
Claude Code's working directory resets between Bash calls. Two approaches:
Option 1: New session (recommended for long work)
gwt switch <branch>
User starts new Claude session in the worktree.
Option 2: Full paths (for quick operations)
WT=$(gwt go my-feature)
cd $WT && bun install
cd $WT && bun run check-types
Parallel worktree operations
Agents can create and operate on multiple worktrees without switching sessions:
gwt new feat/auth
gwt new feat/payments
gwt new fix/bug-123
AUTH_WT=$(gwt go auth)
PAY_WT=$(gwt go payments)
BUG_WT=$(gwt go bug)
cd $AUTH_WT && bun install &
cd $PAY_WT && bun install &
cd $BUG_WT && bun install &
wait
cat $AUTH_WT/src/lib/auth.ts
cd $AUTH_WT && bun run check-types
cd $PAY_WT && bun run test
Spawning parallel agents
For complex parallel work, spawn subagents per worktree:
gwt new feat/a
gwt new feat/b
Each subagent works independently with its worktree path.
Programmatic access
gwt ls --json
gwt here --json
gwt ls --json | jq '.[].path'
Cleanup
gwt rm my-feature
gwt rm my-feature --keep-branch
Git Operations
Worktrees share the same git database as the main repo:
- Same remotes (
origin)
- Same refs (branches, tags)
- PRs created from worktrees target the same repository
cd $(gwt go my-feature)
gh pr create --title "My feature"
Notes
.env files are automatically copied from main repo on creation
- Fuzzy matching works:
gwt go auth matches feat-auth
- Branch slashes become dashes:
feat/auth → repo--feat-auth
- Always run
bun install after creating a worktree
- Worktrees share git remotes/config with main repo
- All worktrees are in one place:
~/code/worktrees/