wt-cli

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 7 Imported by: 0

README

wt

wt creates git worktrees with your local files (env files, editor, installed deps) already in place, so switching to a new branch doesn't mean re-copying .env and waiting for npm install by hand.

$ wt new my-feature
wt: fetching origin...
wt: copied .env
wt: running pnpm install
wt: feature/my-feature  ->  ../myrepo-wt/my-feature

Install

go install github.com/bklimov-web/wt-cli@latest

go install names the binary after the repo directory, so this installs as wt-cli, not wt. Rename it to taste, e.g.:

mv "$(go env GOPATH)/bin/wt-cli" "$(go env GOPATH)/bin/wt"

Or clone and build:

git clone https://github.com/bklimov-web/wt-cli
cd wt-cli
go build -o wt .

Note: wt is a common name — it may collide with another binary on your PATH (some shells ship a wt alias for Windows Terminal, for example). If that happens, rename the built binary or alias it: alias wt=/path/to/wt.

Commands

Command What it does
wt new <name> [branch] Create a worktree branched off origin/<default>, copy env files, run the detected package manager's install, open it in your editor
wt ls List worktrees (branch + path)
wt rm [name] Remove a worktree and its branch, with a confirmation prompt. Interactive picker if name is omitted
wt open [name] Open a worktree in your configured editor. Interactive picker if name is omitted
wt path [name] Print a worktree's path. Interactive picker if name is omitted

Run any command inside your main checkout (or one of its worktrees) — wt resolves the main checkout automatically.

Configuration

wt reads config from two optional TOML files, merged in this order (later wins): defaults → ~/.config/wt/config.toml.wt.toml in your repo root.

# ~/.config/wt/config.toml or <repo>/.wt.toml
worktree_dir    = "../{repo}-wt"     # {repo} is replaced with the repo's dir name
branch_pattern  = "feature/{name}"   # {name} is replaced with the worktree name
editor          = "code"             # command used to open a worktree
env_files       = [".env", ".env.local"]
install_command = ""                 # override auto-detected install command

Install-manager detection is by lockfile: pnpm-lock.yamlpnpm install, yarn.lockyarn install --frozen-lockfile, bun.lockbbun install, package-lock.jsonnpm ci. No lockfile, no install.

Environment overrides

These apply on top of both config files, for one-off use:

Variable Effect
WT_ENV_FILES Space-separated list, overrides env_files
WT_NO_INSTALL Skip the install step
WT_NO_CODE Skip opening the editor

Requirements

  • Git with worktree support
  • Go 1.25+ (only to build from source)

Development

go test ./...
go vet ./...

License

MIT

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
internal
config
Package config resolves wt's configuration by layering defaults, the global config, the per-repo config, and one-off env var overrides.
Package config resolves wt's configuration by layering defaults, the global config, the per-repo config, and one-off env var overrides.
editor
Package editor opens a worktree directory in the configured editor.
Package editor opens a worktree directory in the configured editor.
git
Package git wraps the git plumbing commands wt shells out to.
Package git wraps the git plumbing commands wt shells out to.
installer
Package installer auto-detects a JS package manager from lockfiles and runs its install command.
Package installer auto-detects a JS package manager from lockfiles and runs its install command.
picker
Package picker provides interactive terminal prompts (selection, yes/no confirmation) shared by wt commands that fall back to a picker when the user doesn't name a worktree explicitly.
Package picker provides interactive terminal prompts (selection, yes/no confirmation) shared by wt commands that fall back to a picker when the user doesn't name a worktree explicitly.
worktree
Package worktree orchestrates creating a new git worktree: resolving paths from config templates, branching from origin's default branch, copying env files, and installing dependencies.
Package worktree orchestrates creating a new git worktree: resolving paths from config templates, branching from origin's default branch, copying env files, and installing dependencies.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL