@gitsoufiane/wt0.5.1
Git worktrees in one command: create, switch, list, and delete worktrees, with .env files copied and dependencies installed. Includes an agent skill for Pi, Claude Code, and Codex.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
wt
Git worktrees in one command: create, switch, and clean up,
with your .env files and dependencies ready.
npm install -g @gitsoufiane/wt
wt feature-a # new worktree at ~/.worktrees/<repo>/feature-a
Why wt
Plain Git needs several steps for each new worktree:
git fetch origin
git worktree add -b feature-a ../feature-a origin/main
cp .env ../feature-a/ && cd ../feature-a && npm install
wt feature-a does all of that:
- Safe base. Fetches the remote, then branches from the remote default
branch. If
origin/feature-aexists, it checks it out and tracks it. - Ready to run. Copies untracked
.envand.env.*files and runs the install for your lockfile (npm,pnpm,yarn, orbun), or your own hook. - Easy cleanup.
wt -D feature-aremoves the worktree and the branch. - Script and agent friendly.
--jsonprints one JSON object on stdout.
Install
Requirements: Node.js 18+, Git, and fzf only for wt -s.
| Task | Command |
|---|---|
| Install | npm install -g @gitsoufiane/wt |
| Update | npm install -g @gitsoufiane/wt@latest |
| Uninstall | npm uninstall -g @gitsoufiane/wt |
To install the latest code straight from GitHub, without npm releases:
npm install -g --allow-git=all github:gitsoufiane/wt # main branch
npm install -g --allow-git=all github:gitsoufiane/wt#v0.4.0 # one tag
npm 12 blocks Git sources unless you pass --allow-git=all; older npm
versions do not need it. Both commands put wt on your PATH. Run wt -v
to check.
[!WARNING] The npm name
wt-clibelongs to a different package. If you installed an older version of this tool aswt-cli, runnpm uninstall -g wt-clifirst, and never installwt-clifrom the registry.
Commands
| Command | Does |
|---|---|
wt <name> |
Create a worktree and print its path |
wt --shell <name> |
Create and open a subshell inside it |
wt -s |
Pick a worktree with fzf and print path |
wt --shell -s |
Pick a worktree and open a subshell |
wt -l |
List worktrees with branch and status |
wt -p |
Prune stale worktree metadata |
wt -d [<name>] |
Delete current/named worktree, keep branch |
wt -D [<name>] |
Delete current/named worktree and branch |
wt <name> -D |
Delete named worktree (if any) and branch |
wt sync-env |
Copy untracked .env files |
wt shell-init |
Print the wtc helper that runs cd |
wt -v |
Print version |
Flags:
| Flag | Does |
|---|---|
--base <ref> |
Branch from <ref>; overrides config and tracking |
--root <dir> |
Create the worktree in <dir>/<name> |
--json |
Print JSON on create, delete, switch, and list |
--cwd <dir> |
Run as if started in <dir> |
--no-install |
Skip the setup hook / package install |
--no-env |
Skip copying .env files |
--force |
Discard uncommitted changes when deleting |
Status messages go to stderr, with emoji, colors, and a spinner for each
long step (fetch, worktree add, install). In a terminal, the spinner shows the
last output line of the step; in CI or a pipe, the output streams as plain
lines. NO_COLOR=1 turns colors off. stdout carries only the result: the path
and cd line, or the JSON object with --json.
Daily use
$ wt feature-a
π³ wt v0.3.0 creating worktree feature-a
π¦ repo /Users/me/my-repo
π target /Users/me/.worktrees/my-repo/feature-a
β π°οΈ Fetching latest origin (0.8s)
π± base origin/main
β πΏ Creating branch 'feature-a' from origin/main (61ms)
π copied .env
β π¦ Installing dependencies (npm install) (4.2s)
β¨ Worktree feature-a is ready in 5.3s
/Users/me/.worktrees/my-repo/feature-a
cd '/Users/me/.worktrees/my-repo/feature-a'
A program cannot change the directory of the shell that started it. Pick one:
wt --shell feature-aopens a new shell inside the worktree.- Add this line to
~/.bashrcor~/.zshrc, then runwtc feature-a,wtc -s, orwtc -D. Thewtchelper runswtand moves your shell to the printed path:
eval "$(wt shell-init)"
wt -l marks the current worktree with β and shows clean, changed, or
missing folders. wt -l --json prints an array with path, branch,
name, main, current, dirty, and missing.
Defaults
- Worktrees go in
~/.worktrees/<repo-name>/<branch>, also when you runwtfrom a linked worktree. - If
<remote>/<name>exists,wt <name>checks it out and tracks it, so you can open a teammate's branch. Otherwise the new branch has no upstream. - If the fetch fails (for example, offline),
wtwarns and uses local refs. --base <ref>wins over everything. Without it, the base ref order for new branches is:<remote>/<name>(tracked),WT_BASE,wt.base, the remote default branch,origin/this,origin/main,origin/master, thenHEAD.- The remote is
wt.remote, defaultorigin. - Setup runs
wt.hookif set. Otherwise it runs the install for the detected lockfile.
Config
Set defaults per repo:
git config wt.root ~/Desktop/worktree/my-repo
git config wt.base origin/this
git config wt.remote origin
git config wt.hook 'yarn install'
git config wt.copyEnv false
One-off environment overrides:
WT_ROOT=~/Desktop/worktree/my-repo WT_BASE=origin/this wt feature-a
WT_SKIP_HOOK=1 wt feature-a
WT_COPY_ENV=false wt feature-a
Use with AI agents
Agents should use deterministic commands. Avoid --shell; use the printed
path instead.
wt --json --no-install feature-a
wt --json --no-install --no-env --cwd /path/to/repo feature-a
--json prints one object on stdout, for example
{ "path": "...", "branch": "feature-a", "base": "origin/main", "envCopied": 3 }.
Agent skill
skills/wt/SKILL.md teaches coding agents these rules.
It follows the Agent Skills specification.
The skill only gives instructions, so install the wt command too.
| Agent | Install the skill |
|---|---|
| Claude Code, Codex, Cursor, others | npx skills add gitsoufiane/wt --skill wt -g |
| Pi | pi install npm:@gitsoufiane/wt |
| Pi, from GitHub | pi install git:github.com/gitsoufiane/wt |
The first command uses the skills CLI. The second installs this repo as a Pi package.
Roadmap
- Add
wt repairfor moved worktrees. Git hasgit worktree repairfor this. - Add shell completions for bash, zsh, and fish.
- Remove locked worktrees.
git worktree removeneeds--forcetwice for them, andwt --forcepasses it once.
Development
npm install # dev tools
npm link # use this checkout as the global wt
npm run format:check
npm run lint
npm test
npm pack --dry-run # preview the published files
Release
.github/workflows/publish.yml publishes to npm when you push a v* tag. It
uses trusted publishing, so no
npm token is stored in GitHub, and npm adds provenance for this public repo.
One-time setup:
- Publish the first version by hand. The trusted publisher is set on the
package settings page, so the package must exist:
npm login, thennpm publish.publishConfig.accessmakes the scoped package public. - On npmjs.com, open the package, then Settings -> Trusted Publisher.
Pick GitHub Actions, user
gitsoufiane, repowt, workflowpublish.yml. - Push the next tag within 2 days. npm expires a trusted publisher that has not published within 2 days of its creation.
Each release:
npm version patch # or minor / major; commits and tags vX.Y.Z
git push --follow-tags