What is git stash, and when do you use it?
Quick Answer
git stash saves your uncommitted changes (staged + unstaged) onto a stack and reverts your working directory to a clean state, so you can switch branches or pull. git stash pop reapplies them (and drops the stash entry); git stash apply reapplies without dropping.
git stash takes my current uncommitted changes and puts them aside on a stack, leaving my working directory clean, which is handy when I need to quickly switch branches to fix something and I'm not ready to commit. git stash pop brings the changes back. It's fine for a few minutes of context switching, but for anything longer I'd rather make a throwaway WIP commit on a branch, because a stash is easy to forget and it's only local.
git stash -ualso stashes untracked files;git stash -m "message"names it.git stash list,git stash show -p stash@{1},git stash drop.- Alternative: just make a “wip” commit on a scratch branch — more visible and recoverable than a forgotten stash.
- Stashes are local and not pushed — don't rely on them for anything important.