Stashing Work in Progress

Sam is replacing db/schema.sql with numbered migration files, applied in order by db/index.js, when a tester reports that /api/books?limit=-1 answers with a 500 error. The runner is half written and must not be committed, and switching branches with it in the tree would carry it along. git stash saves the changes and cleans the working tree:

Stashing tracked and untracked changesShell
# Edit db/index.js and add db/migrations/001-create-books.sql: a migration runner
git status -s
git stash push -u -m "Migration runner, half done"
git status -s
git stash list
Output
 M db/index.js
?? db/migrations/
Saved working directory and index state On main: Migration runner, half done
stash@{0}: On main: Migration runner, half done

A stash is a commit (with the index state as a second parent, and with -u a third holding untracked files) referenced by refs/stash; the list is that ref's reflog, so stash@{0} is the newest. Without -u, the new db/migrations/ folder would have stayed behind, untracked, and would now sit in the tree beside the fix; -a also stashes ignored files. Always pass -m: "WIP on main" says nothing a week later.