Read - Simplifying Git Worktrees
Shell functions that reduce git worktree commands to a few keystrokes. No dependencies — just source a file.
git clone https://github.com/backnotprop/worktree-aliases.git ~/.worktree-aliases
cd ~/.worktree-aliases
bash install.shOr manually add to your .zshrc / .bashrc:
source /path/to/worktree-aliases/worktree.sh| Command | What it does |
|---|---|
wtdir |
Show the current worktree directory |
wtdir <path> |
Change the worktree directory for this session |
wt <name> |
Create a worktree + branch off main, cd into it |
wt <name> <base> |
Create a worktree + branch off a specific base, cd into it |
wt -s <name> |
Create a worktree + branch but stay in current directory |
wtr <branch> |
Review a remote branch in a detached worktree, cd into it |
wtr -s <branch> |
Review a remote branch but stay in current directory |
wtrm <name> |
Remove a worktree and delete its branch |
wtrm <name> -k |
Remove a worktree but keep the branch |
wtrm <name> -f |
Remove a worktree and force-delete the branch (even if unmerged) |
wtcd <name> |
Change directory into an existing worktree |
wtl |
List all worktrees |
wtprune |
Prune stale worktree entries |
wt fix-login
# Now in ../fix-login with branch "fix-login" off main
claude # isolated session focused on this fixSlash-style branch names work too — the directory uses dashes:
wt feat/new-parser
# Branch: feat/new-parser
# Directory: ../feat-new-parser
claudewt experiment develop
claude # work against develop instead of main
wt spike HEAD
claude # try a different approach from your current commitwtr feat/new-parser
# Now in ../feat-new-parser, detached — no local branch created
claude # review the code, run tests, leave comments
wtrm feat-new-parser
# Done — no orphan branch to clean upwtrm fix-login
# Removes ../fix-login worktree AND deletes the fix-login branch
wtrm fix-login -k
# Removes the worktree but keeps the branch (e.g., PR is still open)
wtrm abandoned-feature -f
# Removes the worktree and force-deletes the branch (even if unmerged)wtcd fix-login
# cd ../fix-login
wtcd feat-new-parser
# cd ../feat-new-parserwtl # See what's out there
wtrm old-feature
wtrm another-one
wtprune # Clean up any stale entriesBy default, worktrees are created as siblings to your repo (in the parent directory ..). You can change this with WT_DIR:
# Permanently — add to your .zshrc/.bashrc before sourcing worktree.sh
export WT_DIR=~/worktrees
# Per-session
wtdir ~/worktrees
wt fix-login # creates ~/worktrees/fix-login
wtdir # prints: /Users/you/worktreesDefault layout (no WT_DIR set):
~/projects/
├── my-app/ ← your main repo
├── fix-login/ ← wt fix-login
├── feat-new-parser/ ← wtr feat/new-parser
└── experiment/ ← wt experiment develop
Custom layout (export WT_DIR=~/worktrees):
~/worktrees/
├── fix-login/
├── feat-new-parser/
└── experiment/
- Zero dependencies — works with any shell, any git version
- Nothing to install or update beyond sourcing a file
- Easy to read and customize — it's ~60 lines of shell
- If you outgrow these, tools like git-worktree-wrapper exist
The functions are in worktree.sh. Fork and edit to match your workflow. Common tweaks:
- Change the default base branch from
maintomasterordevelop - Add a post-create hook (e.g., auto-run
npm installafterwt) - Set
WT_DIRto put all worktrees in a dedicated folder