Fast git worktree creation across all the repos you work on.
go install github.com/mehran-prs/wt@latestwt new <repo-or-alias> <branch>wt new github.com/mehran-prs/snip my-feature # first time: asks for an alias to save it under
wt new snip another-feature # later: reuse it by that alias
cd "$(wt new snip my-feature)" # only the worktree path goes to stdout, so this just worksAny repo location git understands works: a local path, a full URL, an ssh
remote, or a bare host/org/repo shorthand.
Details:
- The first time you use a repo,
wtasks you to pick an alias for it and clones it into its cache. The next time, use that alias instead. - If you type an alias that isn't cached yet,
wtasks you to paste the repo path/URL instead, clones it, and remembers it under that alias. - Before creating the worktree,
wtfetches and fast-forwards the primary branch (masterif it exists, otherwisemain). - Branch resolution:
- exists locally already -> just checked out into the new worktree.
- exists on
originbut not locally -> checked out and tracksorigin/<branch>. - doesn't exist anywhere -> created from the primary branch, without tracking it as upstream.
- The worktree is created at
$WT_WORKTREE_DIR/<alias>-<branch>(default~/wt/<alias>-<branch>).
wt pathPrints $WT_WORKTREE_DIR (default ~/wt) to stdout.
wt keeps a small local cache of repos you've used before, each under a
short alias, and reuses that cache to create new worktrees in seconds.
wt alias remove <alias>Removes the alias from the cache. Any worktrees already created from it are left untouched — that's on you to clean up.
| Env var | Default | Purpose |
|---|---|---|
WT_WORKTREE_DIR |
~/wt |
Where new worktrees are created |
WT_CACHE_DIR |
~/.wt |
Where cloned repos and aliases are stored |
wt supports alias, branch, and command completion (branches complete once
the first argument is a cached alias). Generate a script for your shell and
source it, e.g. for zsh:
wt completion zsh > "${fpath[1]}/_wt"Run wt completion --help for bash/fish/powershell instructions.