rescue-a-shared-checkoutlisted
Install: claude install-skill damson/hard-won-skills
# Rescue a shared checkout
Uncommitted work in a tree with more than one writer is the least safe state a
repository has. Nothing records who wrote it, nothing preserves it, and the next
branch cut from that tree carries it by accident. Both obvious moves are wrong:
discarding it destroys work nobody can recover, and committing it all lands
half-written edits under your name.
The job is separating what is already safe from what is genuinely at risk. Most
of a shared tree's dirt is neither.
## Procedure
### 1. Classify every dirty path before touching any of it
A path is dirty for three reasons and only one needs rescuing. Compare against
the branch you would land on, not local `HEAD`: a checkout behind its remote
shows already-merged work as new.
```bash
REMOTE=${REMOTE:-origin}
BASE=${BASE:-develop} # the branch this tree's work would land on
# A failed fetch leaves a stale ref that still resolves, so the loop would
# answer confidently against the wrong commit. Stop instead.
git fetch "$REMOTE" --quiet || { echo "fetch failed; not classifying against a stale ref"; exit 1; }
git rev-parse --verify --quiet "$REMOTE/$BASE^{commit}" >/dev/null ||
{ echo "no such branch: $REMOTE/$BASE"; exit 1; }
# -z, because the default format QUOTES a path containing a space or a quote and
# every git call downstream then takes the quotes literally. --untracked-files=all,
# because the default collapses an untracked directory into one record that is not
# a file. Under -z a rename