What Is git stash?
git stash temporarily sets aside your uncommitted changes so you can switch context with a clean working directory, then restore them later.
git stash is the quick way to put your current work on a shelf. When something urgent comes up and you are not ready to commit, stashing tucks your uncommitted changes away, gives you a clean slate, and lets you bring the work back when you return.
What stashing does
Stashing records your uncommitted modifications, both staged and unstaged, and reverts your working directory to the last commit. The changes are saved on a stash stack you can reapply later. It is a lightweight pause button, not a commit, and stays entirely on your machine.
Stashing and restoring
You stash, do the urgent work, then pop the stash to bring your changes back.
git stash push -m "WIP form layout"
# handle the interruption
git stash popWhen stashing helps
Stashing is handy when you need to switch branches to fix something urgent, pull in updates onto a clean tree, or temporarily clear changes to test a clean build. You can keep multiple stashes and apply them selectively, though deep stash stacks get confusing.
Stash and CI/CD
Stashes are purely local and are never pushed, so CI never sees them. That is by design: a pipeline builds committed history, not someone's shelved work in progress. If you want CI to test something, you must commit and push it; stashed changes simply do not exist on the remote.
Using stash wisely
- Stash to switch context without committing half-done work.
- Add a message so you remember what each stash holds.
- Avoid letting stashes pile up and grow stale.
- Remember stashes are local; commit to get changes into CI.
Key takeaways
- git stash shelves uncommitted changes for a clean working directory.
- You restore them later with pop or apply from the stash stack.
- Stashes are local only; CI builds committed history, not stashes.