← ClaudeAtlas

rescue-a-shared-checkoutlisted

Use when a working tree you do not exclusively own carries uncommitted changes somebody else wrote — a second agent session, a colleague's machine, a long-lived VM, a tool that wrote into the tree behind you. Fires on "whose changes are these", "the tree is dirty and it isn't mine", "sort out the pending changes", and before cutting a branch from a tree whose dirt you did not create. Do NOT fire for your own uncommitted work, or for a tree you are certain nothing else writes to.
damson/hard-won-skills · ★ 1 · AI & Automation · score 67
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