git-wtclean is a Git subcommand for cleaning linked worktrees. By default it operates on the current repository; with --all it spans every repository managed by ghq.
It uses Git's native worktree commands:
git worktree list --porcelain -zgit worktree removegit worktree remove --forcegit worktree prune
It does not delete branches.
This tool is inspired by k1LoW/git-wt, but does not depend on it.
go install github.com/rokuosan/git-wtclean/cmd/git-wtclean@latestMake sure the installed git-wtclean binary is in your PATH. Git will then expose it as:
git wtcleanBy default, git wtclean operates on the repository containing the current directory. Run it outside a Git repository and it errors, suggesting --all.
Dry-run by default:
git wtcleanRemove linked worktrees:
git wtclean -dForce remove linked worktrees:
git wtclean -DPrune stale worktree metadata:
git wtclean --pruneTarget every repository listed by ghq list -p instead of just the current one:
git wtclean --all
git wtclean --all -d
git wtclean --all --prunePrint each repository while pruning:
git wtclean --prune --verbose
git wtclean --prune -vBy default, git wtclean resolves the current repository and targets its linked worktrees:
git worktree list --porcelain -zWith --all, it instead iterates over every repository reported by ghq:
ghq list -p
git -C <repo> worktree list --porcelain -zIn either case, the first worktree entry is treated as the primary worktree and is skipped. Bare worktree entries are also skipped.
With -d, each target is removed with:
git -C <repo> worktree remove <path>With -D, each target is removed with:
git -C <repo> worktree remove --force <path>--prune runs:
git -C <repo> worktree pruneThis only cleans stale Git worktree metadata, such as records left after a worktree directory was removed manually. By itself, --prune does not inspect or remove active linked worktrees. It does not remove branches.
Use -h for the built-in help:
git wtclean -hWhen invoked as a Git subcommand, git wtclean --help is handled by Git itself and opens the git-wtclean(1) man page if installed.
This repository uses mise for tool versions and tasks.
mise run format
mise run lintYou can also run the Go checks directly:
go test ./...
go vet ./...
golangci-lint run