Manage git worktrees for the current repository.
Parse $ARGUMENTS to determine the subcommand:
Subcommands
new <branch-name> [base-ref] (default if just a name is given)
- •Determine the repo root with
git rev-parse --show-toplevel - •Derive the repo basename (e.g.
my-project) - •Create worktree at
../<repo-basename>.<branch-name>/frombase-ref(default:main) - •Run:
git worktree add ../<repo-basename>.<branch-name> -b <branch-name> <base-ref> - •Print the path and suggest
cdcommand
list
- •Run
git worktree list --porcelainand parse output - •For each worktree, show:
- •Path
- •Branch name
- •Last commit (short hash + subject via
git log -1 --format='%h %s') - •Dirty status (
git -C <path> status --porcelain | head -1)
- •Format as a clean table
clean
- •Run
git worktree list --porcelainto find all worktrees - •Identify stale worktrees (missing directories or branches deleted from remote)
- •Run
git worktree pruneto remove stale entries - •List what was pruned
- •Optionally suggest worktrees whose remote branches are gone
If $ARGUMENTS is empty, default to list.