worktrees
gw creates Git worktrees and removes finished branches after checking for
unmerged work. It recognizes squash merges and lists ignored files before
deleting a checkout. The fish and zsh plugins let you switch worktrees
without typing paths.
Install
Install uv, then install the commands:
uv tool install git-worktrees
The package requires Python 3.11 or newer and has no Python runtime dependencies. Use Git 2.39 or newer for squash-merge detection. Partial clones have additional Git version requirements.
The install provides gw and its long name, worktrees. If uv reports that
its executable directory is missing from PATH, run uv tool update-shell
and restart your shell. Upgrade the commands with uv tool upgrade git-worktrees.
The commands work from any shell. Install the matching fish or zsh plugin
for completions, shortcuts and directory changes. Pin the plugin to the
release that gw version reports; an unpinned plugin follows main, which
can contain unreleased changes.
fish
With Fisher installed, run:
fisher install MihaiBojin/worktrees@v0.14.0
To change release, edit the tag in $__fish_config_dir/fish_plugins, then
run fisher update. Use the same procedure to pin an untagged installation.
zsh
With Antidote installed, add this line to its plugin
list, normally ~/.zsh_plugins.txt, and open a new shell:
MihaiBojin/worktrees branch:v0.14.0 path:zsh/plugins/worktrees
Completion needs compinit. If your shell configuration does not run it,
add this after the plugin loads:
autoload -Uz compinit && compinit
To change the tag, first remove Antidote's clone:
antidote purge MihaiBojin/worktrees
Then edit the tag in the plugin list and open a new shell. Editing the list after the purge makes Antidote rebuild its generated bundle.
Check the installation
Run gw --help. With matching command and shell releases, its output
includes:
worktrees 0.14.0: git worktree commands that refuse to lose work
The shell plugin here is 0.14.0, the same release as these commands.
Upgrade the commands and the shell plugin together. For development from a clone, see Working on a checkout.
Quickstart
Run commands inside the repository you want to manage. The repository must
have a commit and a resolvable head branch,
usually the default remote's default branch, or local main or master.
Create a worktree on a new branch named fix-parser. This example works in
bash and zsh with or without the shell plugin:
cd "$(command gw add fix-parser -q)"
git branch --show-current
The second command prints:
fix-parser
For a main checkout at /path/to/repo, the new checkout is at
/path/to/.worktrees/fix-parser/repo. With the fish or zsh plugin loaded,
gw add fix-parser creates the checkout and changes directory in one call.
If the branch already exists, gw add uses it; a branch that exists only
on the remote needs confirmation or --yes.
Use gw list to choose another worktree. Type to filter, use the arrow keys
to move, and press enter to select. gw list fix-parser selects a unique
match directly. Without a terminal, gw list prints metadata. The shell
plugin performs the directory change.
Commands
gw --help lists every command and shortcut. Each command's --help
describes its flags. The guides cover these tasks:
| Command | Task |
|---|---|
gw add NAME [BASE] |
Create a worktree for a new or existing branch |
gw list [QUERY] |
Choose a worktree or list matching checkouts |
gw select-main |
Go to the worktree on the head branch |
gw sync |
Refresh remote refs and GitHub or GitLab evidence |
gw prune |
Assess worktrees and remove eligible ones after confirmation |
gw remove [NAME|PATH] |
Assess or remove one worktree |
gw branch status [NAME ...] |
Assess branches without worktrees |
gw branch prune [NAME ...] |
Delete eligible branches without worktrees |
gw branch create NAME |
Start a branch in the current checkout |
gw fast-forward [NAME] |
Update a branch, or continue from a finished branch on a new one |
gw push |
Push with checks for remote work and previously merged commits |
gw ci-checks [NUMBER] |
Read or wait for checks on a GitHub pull request or GitLab merge request |
gw merge NUMBER... |
Squash checked GitHub pull requests, including native stacks |
gw stack-link NUMBER NUMBER ... |
Link GitHub pull requests into a native stack |
gw preflight |
Check repository and plugin setup |
gw version |
Print the installed version |
A shortcut such as gwa is a shell function that calls gw add. Only gw
and worktrees are installed as executables.
Assess and remove
Preview worktree removal as JSON:
gw prune --json
The verdicts array gives each worktree's reason, eligible status and
protections. Use eligible to decide whether removal is permitted.
gw prune --table prints the assessment as text. Neither preview removes
worktrees or branches; assessments can save proof caches and sync first.
WARNING: Copy any ignored files that you need before removal. Removing a worktree deletes its ignored files, including virtual environments and build output. Git cannot restore those files.
On a terminal, assess and confirm eligible removals with:
gw prune
The command lists each checkout, ignored path and branch that it will
delete. It prints restore commands for branches and approved stashes.
Press y to confirm; any other key cancels. The command reassesses before
removal and refuses targets that changed.
gw remove NAME applies the same checks to one worktree. Use a quoted
absolute path when names are ambiguous. Without a terminal, or with
--json or --table, both commands assess only. --yes approves removal
but grants no additional deletion permission. Removing the current
worktree always needs a second terminal confirmation.
The main checkout and dirty worktrees stay. Untracked files, active
operations and submodule stores also block removal. The branches main,
master and the head branch cannot be deleted. Other protections require
explicit permission:
| Flag | Permits |
|---|---|
--delete empty |
An unused branch and its checkout |
--delete closed |
A branch whose request closed without merging its current tip |
--delete stashes |
Stashes associated with the branch |
--delete reflog |
Commits held only by reflogs that removal deletes |
--delete stale-lock |
Unlocking a worktree whose recorded process has exited |
--delete all |
All the categories above |
Repeat --delete to combine categories. --keep-branch retains the branch
and its stashes while removing an otherwise unprotected checkout. It
accepts only --delete reflog and --delete stale-lock; a detached
checkout still needs proof that its commits are finished.
See protections and permissions for the checks, and deletion and recovery for partial failures and restore commands. Restore branches or stashes before Git garbage collection removes their unreachable commits.
Shortcuts
The shell plugins provide these removal shortcuts:
| Shortcut | Runs |
|---|---|
gwp |
gw prune |
gwp! |
gw prune --yes |
gwpa |
gw prune --delete all |
gwpa! |
gw prune --delete all --yes |
gwr |
gw remove |
gwr! |
gw remove --yes |
gwrk! |
gw remove --keep-branch --yes |
Head and synchronization
gw sync fetches every remote and asks GitHub or GitLab about local branch
tips. GitHub needs an authenticated gh; GitLab needs an authenticated
glab. With several remotes, set Git's checkout.defaultRemote to select
the remote used for assessments.
Assessments sync first when the default remote has never synced or its
last sync is at least 300 seconds old. WORKTREES_SYNC_TTL changes that
interval in whole seconds. A failed sync warns and the assessment proceeds
with available evidence. gw list reads local worktree records without
syncing.
gw fast-forward fetches the default remote when sync is due and reads
fresh request evidence when needed. It can fetch again when a merged
request names a commit missing locally. gw push fetches on every run.
Both refuse when a required fetch or request query fails.
Set WORKTREES_OFFLINE=1 to prevent network access. Local assessment and
navigation still work; commands that require the network refuse. See
head and evidence and
sync cache for fallback rules and partial
sync outcomes.
Output and JSON
Results go to stdout; diagnostics and prompts go to stderr. JSON results
are objects with head and lastSync. Worktree and branch assessments put
rows in verdicts; navigation puts rows in worktrees.
With jq installed, list paths or select eligible rows:
gw list --json | jq -r '.worktrees[].path'
gw prune --json | jq '.verdicts[] | select(.eligible)'
The first command prints one path per worktree. The second prints eligible assessment rows and removes nothing. JSON preserves paths as strings; keep paths quoted when passing them to a command.
--json disables colour. -q suppresses summaries where supported, while
-v traces subprocesses on stderr. See JSON and streams
for fields and the commands that accept each flag.
Commands append an audit log under
~/.local/state/worktrees, or $XDG_STATE_HOME/worktrees when set.
WORKTREES_AUDIT_DIR changes the directory; WORKTREES_AUDIT=off disables
logging. Help and completion record nothing.
What it refuses
The CLI refuses these Git operations regardless of command flags:
reset --hard
a forced checkout or switch
clean -f
push --force
worktree remove --force
branch -D
an update-ref delete that names no full sha
a forced fetch into a local ref
gw --explain lists the Git commands that the CLI can run and the guard
rules that apply to them.
Agent plugin
The agent plugin provides six skills for Claude Code and Codex. They update branches through conflicts, inspect checks, maintain pull request descriptions, ship changes through merge, prune approved worktrees and configure permissions.
Install the plugin from the mihaibojin marketplace as its README
describes, then run gw preflight inside each repository. The
preflight guide explains each check and how
to install the current client's permission rules. The skills use the
checkout assigned to the session.
Migration
See the migration table for renamed commands
and flags. Scripts that act on assessments must check eligible before
removal; a remove verdict alone does not grant permission.
Contributing
DEVELOPMENT.md lists the setup and checks for a contribution. Report bugs through GitHub issues. The reference documents shared rules and links to every command guide.
Licence
Apache-2.0, Mihai Bojin. See LICENSE.
Metadata
Release files for git-worktrees 0.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| git_worktrees-0.14.0.tar.gz | 459.7 kB | With provenance | Details for git_worktrees-0.14.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| git_worktrees-0.14.0-py3-none-any.whl | Python 3 | none | any | Details for git_worktrees-0.14.0-py3-none-any.whl |
Total release size: 612.9 kB
Release files / git_worktrees-0.14.0.tar.gz
| Download URL | git_worktrees-0.14.0.tar.gz |
|---|---|
| Size | 459.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
98017037b1e0619263ef944715e37962979751fd8a58220ccb707f4f57dbc86f
|
|
BLAKE2b-256 checksum How to use checksums |
7e0228ef5bd575139bd58e294831cb290ec12d4d618bab0e53055b75aa63ae94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / git_worktrees-0.14.0-py3-none-any.whl
| Download URL | git_worktrees-0.14.0-py3-none-any.whl |
|---|---|
| Size | 153.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db561ff07a1f02aa08fd86ca79669416d8fd67d9fe7fc14f6b7bee3e45f571ca
|
|
BLAKE2b-256 checksum How to use checksums |
a6b5f0b57422a109fd180c0433ddca00ff85a35c204c94de7c364754f897fa98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for git-worktrees 0.14.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for git_worktrees-0.14.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.