glossary

Git Stash

A git feature that temporarily shelves uncommitted changes (both staged and unstaged) so you can work on something else, then reapply them later.

Git stash records the current state of the working directory and index in a stack-like data structure, then reverts them to the clean HEAD state. This is useful when you need to switch branches urgently (e.g., to fix a production bug) but have uncommitted work in progress that is not ready to commit. Changes are saved to a stash stack. You can have multiple stashes, each identified by a reference like stash@{0}, stash@{1}, etc. Each stash entry optionally includes a message (git stash push -m "message") for identification. The most recent stash is always stash@{0}. Common operations include git stash push (save changes), git stash pop (apply and remove the top stash), git stash apply (apply without removing), git stash list (view all stashes), and git stash drop (remove a specific stash). Stashing only tracks tracked files by default; untracked files require the --include-untracked flag, and ignored files require --all.

git stash push -m 'WIP: refactoring auth middleware'
git stash pop # apply and remove the latest stash
git stash list # list all stashes
git stash show stash@{1} # show diff of a specific stash
git stash branch new-feature stash@{0} # create a branch from a stash

git-agent encourages committing early and often by making commit creation fast and low-effort. Instead of stashing work-in-progress to switch context, you can let git-agent create a meaningful atomic commit from your current changes, reducing the need for stashes and the risk of forgetting about them.

brew install gitagenthq/brew/git-agent
What is the difference between git stash pop and git stash apply?
pop applies the stash and removes it from the stack. apply applies the stash but keeps it in the stack, allowing you to apply the same stashed changes to multiple branches.
Can I recover a dropped stash?
A dropped stash can be recovered if you know its commit hash. Each stash is a commit object in git. Use git fsck --lost-found or git reflog to find the orphaned commit, then git cherry-pick or git stash apply with the commit hash.
Does git-agent stash changes before splitting?
No. git-agent works directly with the repository's working-tree diff. It does not stash anything. The autonomous handoff discovers the current changes, stages its planned groups, and commits them without requiring a separate staging step.