← Field notes

August 31, 2026 · 2 min read

How to clean up git worktrees without losing work

A practical checklist for removing stale git worktrees safely - what to verify before rm, and how to automate the boring parts.

Git worktrees are the natural unit of work for AI coding agents: one branch, one directory, one dev server. They’re also the natural unit of mess, because removing one is a small act of destruction - and nobody wants to be the person who deleted an unpushed fix.

Here’s the checklist we use before removing any worktree, and how to run it by hand.

1. List what you actually have

git worktree list

Run this from the main checkout of each project. Anything marked prunable points at a directory that no longer exists - those records are safe to clear immediately:

git worktree prune

2. Check for uncommitted changes

git -C /path/to/worktree status --porcelain

Any output at all means work you’d lose. Stop here for that worktree.

3. Check for unpushed commits

git -C /path/to/worktree log --oneline @{upstream}..HEAD

Commits listed here exist only on your machine. If the branch has no upstream at all, treat it as unpushed - it lives nowhere else.

4. Check the branch actually merged

git -C /path/to/main-checkout branch --merged origin/main

If the worktree’s branch appears in this list, its history is preserved in main and the worktree adds nothing.

5. Check nothing is still running from it

The part everyone forgets. A worktree can look inert while a Docker stack or dev server still runs from its directory:

lsof +D /path/to/worktree 2>/dev/null | head
docker ps --format '{{.Names}}\t{{.Mounts}}' | grep worktree-name

Kill or docker compose down whatever you find before removing the directory, or you’ll strand containers with bind mounts into nothing.

6. Only then remove

git worktree remove /path/to/worktree

git worktree remove refuses dirty worktrees by default - one last guardrail.

For whole abandoned projects: archive, don’t delete

For projects you haven’t touched in months, skip the per-worktree audit and move the whole thing aside:

mkdir -p ../_archived && mv project ../_archived/

Every file survives, dirty work included, and restoring is a mv back. Disk space is cheap; deleted work isn’t.


Or let something run the checklist for you

This checklist is exactly what Clueprint automates. It scans every project on your Mac, runs all six checks continuously, and shows a review flow of what’s safe - stalest first, with the checks spelled out per worktree. Dirty and unpushed worktrees are never removable, running stacks are stopped properly first, and abandoned projects get the archive treatment. Nothing happens without your confirmation, and every action re-verifies on a fresh scan before it runs.

Free for macOS 14+.