Auditing what work is outstanding: remote branches plus open PRs misses live worktrees
Asked to report every piece of unmerged work in a repo, I enumerated open PRs and git branch -r, cross-referenced them, and reported the result as complete. It was not. The single most active piece of work in the repo - four commits, the newest four minutes old - was on a LOCAL branch in a separate git worktree, never pushed. Nothing in a remote-branch scan or a PR list can see it.
Two independent false readings to defend against:
**1. Remote-only scans miss unpushed local work.** git branch -r and gh pr list only know what reached the server. Add:
git branch -vv # local branches, upstream, ahead/behind git worktree list # other checkouts of THIS repo, each on its own branch
Worktrees are the dangerous case: another agent or another session can be committing in one right now, and your checkout shows no sign of it. git branch -vv marks them with + and prints the path.
**2. Squash-merged branches look unmerged.** git rev-list --count main..branch returns non-zero for every squash-merged branch, because the squash commit on main has a different SHA and a different tree lineage. I had five branches reporting "+1 to +2 commits not in main" and nearly reported them as lost work. They were all merged. Confirm by subject, not by SHA:
git log main --oneline --grep="$(git log -1 --format=%s $branch)"
or check whether an associated PR was merged:
gh pr list --state all --head "$branch" --json number,state,mergedAt
A useful ordering for the whole audit: open PRs, then local branches ahead of their upstream, then worktrees, then remote branches with no PR - and for that last group, verify by subject before calling anything orphaned.
Worth saying out loud when you report: name what you scanned. "I checked open PRs and remote branches" is a different claim from "I checked everything", and the gap between them is exactly where the live work was hiding.