A thin shell wrapper for git worktree with tab completion.
Clone the repo (or just download wt.sh) to wherever you'd like, ~/.wt-cli is an example of where you could put it:
git clone https://github.com/stilliard/wt-cli.git ~/.wt-cliThen add to your ~/.zshrc or ~/.bashrc, adjusting the path to match where you saved it:
source ~/.wt-cli/wt.shThen reload your shell (source ~/.zshrc) or open a new terminal.
wt # list all worktrees
wt <name> # cd into worktree by branch name
wt mk <branch> # create worktree as sibling of current repo and cd into it
wt mk <branch> <path> # create worktree at a specific path and cd into it
wt rm <name> # remove a worktree
wt prune # prune stale worktree refs
wt ls # list worktrees (same as bare wt)
wt cd <name> # explicit cd (same as wt <name>)
wt help # show usageAliases: add → mk, remove → rm, list → ls
Tab completion works for subcommands and branch names in both bash and zsh.
Place executable scripts in .wt-hooks/<event> at your repo root to run custom logic around worktree operations.
| Event | When | Runs in |
|---|---|---|
pre-mk |
Before creating a worktree (non-zero exit aborts) | Original repo |
post-mk |
After creating a worktree | New worktree |
pre-rm |
Before removing a worktree (non-zero exit aborts) | Worktree being removed |
post-rm |
After removing a worktree | Original repo |
Each hook receives the branch name and path via env vars WT_BRANCH and WT_PATH. The standard OLDPWD is also available, pointing to the directory you were in before the worktree was created.
Example - copy env and install dependencies after creating a worktree:
#!/bin/sh
# .wt-hooks/post-mk (runs inside the new worktree)
cp "$OLDPWD/.env" .env
npm installchmod +x .wt-hooks/post-mkwt mk and wt rm also accept --pre-hook PATH and --post-hook PATH flags to run a single script for one invocation, without committing it to .wt-hooks/. The script receives the same WT_BRANCH / WT_PATH env vars; a failing --pre-hook aborts the operation.
wt mk feature-x --post-hook ./my-setup.sh
wt rm feature-x --pre-hook ./my-teardown.shA new worktree is a fresh checkout, so untracked files like .env are not present in it. List the paths you want carried over in a .worktreeinclude file at your repo root, using .gitignore syntax:
# .worktreeinclude
.env
.env.local
.claude/settings.local.json
On wt mk, any file that matches a pattern and is gitignored is copied into the new worktree. Tracked files are never duplicated. This is the same file Claude Code uses for claude --worktree, so one config serves both tools.
- git 2.5+
- bash or zsh
Tests use bats-core. Install it, then:
# Ubuntu/Debian
sudo apt install bats
# macOS
brew install bats-corebats test/wt.bats