https://github.com/stilliard/wt-cli
`wt` helper for working with git worktrees, e.g. easily list and cd into them, with autocomplete!
https://github.com/stilliard/wt-cli
git git-worktree worktree-manager worktree-workflow worktrees
Last synced: about 8 hours ago
JSON representation
`wt` helper for working with git worktrees, e.g. easily list and cd into them, with autocomplete!
- Host: GitHub
- URL: https://github.com/stilliard/wt-cli
- Owner: stilliard
- License: mit
- Created: 2026-05-18T21:37:15.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2026-05-18T22:23:40.000Z (about 2 months ago)
- Last Synced: 2026-05-19T00:43:38.216Z (about 2 months ago)
- Topics: git, git-worktree, worktree-manager, worktree-workflow, worktrees
- Language: Shell
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wt
A thin shell wrapper for `git worktree` with tab completion.
## Install
Clone the repo (or just download `wt.sh`) to wherever you'd like, `~/.wt-cli` is an example of where you could put it:
```sh
git clone https://github.com/stilliard/wt-cli.git ~/.wt-cli
```
Then add to your `~/.zshrc` or `~/.bashrc`, adjusting the path to match where you saved it:
```sh
source ~/.wt-cli/wt.sh
```
Then reload your shell (`source ~/.zshrc`) or open a new terminal.
## Usage
```sh
wt # list all worktrees
wt # cd into worktree by branch name
wt mk # create worktree as sibling of current repo and cd into it
wt mk # create worktree at a specific path and cd into it
wt rm # remove a worktree
wt prune # prune stale worktree refs
wt ls # list worktrees (same as bare wt)
wt cd # explicit cd (same as wt )
wt help # show usage
```
Aliases: `add` → `mk`, `remove` → `rm`, `list` → `ls`
Tab completion works for subcommands and branch names in both bash and zsh.
## Hooks
Place executable scripts in `.wt-hooks/` 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:
```sh
#!/bin/sh
# .wt-hooks/post-mk (runs inside the new worktree)
cp "$OLDPWD/.env" .env
npm install
```
```sh
chmod +x .wt-hooks/post-mk
```
### Ad-hoc hooks for testing
`wt 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.
```sh
wt mk feature-x --post-hook ./my-setup.sh
wt rm feature-x --pre-hook ./my-teardown.sh
```
## Copying gitignored files into new worktrees
A 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:
```text
# .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.
## Requirements
- git 2.5+
- bash or zsh
## Tests
Tests use [bats-core](https://github.com/bats-core/bats-core). Install it, then:
```sh
# Ubuntu/Debian
sudo apt install bats
# macOS
brew install bats-core
```
```sh
bats test/wt.bats
```
## License
[MIT](LICENSE)