A zsh function for managing git worktrees with minimal friction.
- Short numeric aliases for worktrees (
wt 1,wt 2, etc.) wt 0orwt hometo return to main repowt -to jump to previous worktree- Auto-creates worktree when navigating to an existing branch
- Configurable file copying and hooks via
.worktreeconfig wt statusoverview of all branches and worktrees
-
Copy
wtto your zsh functions directory:cp wt ~/.zsh/functions/ -
Source it in your
.zshrc:source ~/.zsh/functions/wt
wt [go] <#|branch> go to worktree (creates if branch exists)
wt [go] 0|home go to main repo
wt [go] - go to previous worktree
wt new <branch> create new branch and worktree
wt rm <#|branch> remove worktree
wt rm -b <#|branch> remove worktree and delete branch
wt list list worktrees (raw)
wt status show branches and worktree status
wt new feature-x # Create new branch and worktree
wt 1 # Go to worktree 1
wt feature-x # Go to worktree by branch name
wt 0 # Go back to main repo
wt - # Go to previous worktree
wt rm 1 # Remove worktree 1
wt rm -b feature-x # Remove worktree and delete branch
wt status # Show all branches and their worktree numbersparent/
project/ # Main repo (home, [0])
project-worktrees/
project-worktree-1/ # [1]
project-worktree-2/ # [2]
Create a .worktree file in your repo root:
[copy]
# Files to copy when creating a new worktree
.env
**/.claude/settings.local.json
[setup]
# Commands run from parent dir after worktree creation
# $WT_DIR is the path to the new worktree
mise trust "$WT_DIR"
[init]
# Commands run inside the new worktree after creation
npm install- [copy] - Glob patterns for files to copy from home repo to new worktrees. Supports
**for recursive matching. - [setup] - Commands run from the parent directory after
git worktree add. Use$WT_DIRto reference the new worktree path. Useful formise trust,direnv allow, etc. - [init] - Commands run inside the new worktree. Useful for
npm install,bundle install, etc.
Note: You can globally ignore
.worktreefiles by adding them to~/.config/git/ignore.
- zsh
- git