From devops-toolkit
Use when creating git worktrees for parallel development, setting up isolated workspaces for Claude Code agents, navigating between worktrees, or cleaning up worktrees after branches are merged. Covers the `gwt` shell function and `.worktrees/` directory convention.
How this skill is triggered — by the user, by Claude, or both
Slash command
/devops-toolkit:git-worktree-managerThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Manage git worktrees using the `gwt` shell function and the `.worktrees/` directory convention. Worktrees enable parallel development on multiple branches from a single repository without stashing or switching branches.
Manage git worktrees using the gwt shell function and the .worktrees/ directory convention. Worktrees enable parallel development on multiple branches from a single repository without stashing or switching branches.
Worktrees live inside the repository root under .worktrees/:
~/src/github.com/org/repo/ # main branch (bare checkout)
├── .worktrees/ # all worktrees live here
│ ├── feat-new-api/ # feature branch worktree
│ ├── bug-fix-auth/ # bugfix branch worktree
│ └── refactor-db-layer/ # refactor branch worktree
├── .gitignore # contains .worktrees entry
├── src/
└── ...
This layout keeps worktrees colocated with the repo for easy discovery and navigation. The .worktrees/ directory is automatically added to .gitignore by gwt.
gwt Shell FunctionDefined in ~/.zshrcd/conf.d/git-worktree.zsh and auto-sourced by zsh.
cd ~/src/github.com/org/repo # navigate to repo root
gwt feat-new-api # creates .worktrees/feat-new-api
Behavior:
origin, creates a tracking branch.worktrees is listed in .gitignoregwt -l
gwt -d feat-new-api
Prompts whether to also delete the branch after removing the worktree.
gwt -h
cd .worktrees/feat-new-api
# or with tab completion:
cd .worktrees/feat-<TAB>
cd .worktrees/feat-new-api
claude # starts Claude Code scoped to this worktree
Claude Code inherits the worktree's working directory and branch context. Each worktree is a fully independent working directory with its own staged/unstaged changes.
code .worktrees/feat-new-api
# From repo root, target a worktree directly
make -C .worktrees/feat-new-api test
git -C .worktrees/feat-new-api status
When Claude Code agents use isolation: "worktree", they create temporary worktrees via the internal Task tool mechanism. The gwt function serves a different purpose: user-initiated, persistent worktrees for parallel development sessions.
gwt vs Agent Worktrees| Scenario | Use gwt | Use agent isolation: "worktree" |
|---|---|---|
| User wants to work on a feature branch | Yes | No |
| Agent needs temporary isolation for a task | No | Yes |
| User wants to run Claude in a branch | Yes | No |
| Agent making speculative changes | No | Yes |
| Long-lived parallel development | Yes | No |
gwt to UsersWhen a user asks to "work on a feature branch", "start a new branch", or "set up parallel development", suggest using gwt:
# From the repo root
gwt feat-branch-name
cd .worktrees/feat-branch-name
claude # or: code .
gwt feat-new-api from repo rootcd .worktrees/feat-new-api and work normallygit push -u origin feat-new-apigwt -d feat-new-api# From repo root
gwt -d feat-new-api # removes worktree, prompts to delete branch
gwt -l # shows all worktrees with their branches and paths
gwt automatically ensures .worktrees is in the repo's .gitignore. If the line is missing, it appends it. This prevents worktree directories from being committed to the repository.
If .gitignore doesn't exist, gwt creates it with .worktrees as the first entry.
| Task | Command |
|---|---|
| Create worktree | gwt <branch-name> |
| List worktrees | gwt -l |
| Remove worktree | gwt -d <branch-name> |
| Navigate to worktree | cd .worktrees/<branch-name> |
| Run Claude in worktree | cd .worktrees/<branch> && claude |
| Open in VS Code | code .worktrees/<branch-name> |
gwt function lives in ~/.zshrcd/conf.d/git-worktree.zshgwt function with yadmnpx claudepluginhub knowledgexhunta/devops-toolkit --plugin devops-toolkitGuides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.