Git Stash Explained: Save and Restore Unfinished Work
Git stash parks unfinished changes without committing, then lets you inspect and restore them when priorities shift, without losing your edits.

tl;dr the short answer
Git stash is a way to save uncommitted changes temporarily, returning your working tree to the last commit so you can switch tasks without making a commit. Stashes can hold staged and unstaged edits, stack up for later, and be applied or popped when you’re ready; by default, they skip untracked files and stay only on your machine. Use clear stash names, inspect entries before restoring them, and remember that changes may conflict with newer work, so a stash is a pause button, not a backup.
Ever been halfway through a waybar tweak when something else suddenly needs your attention? You don’t want to commit half-finished edits, but you don’t want to lose them either. That’s where git stash comes in.
It works like a shelf for unfinished work: it tucks away your uncommitted changes (edits Git hasn’t saved as a commit yet) and leaves your project clean, so you can switch tasks and bring everything back later.
This guide covers creating, inspecting, and reapplying stashes, handling conflicts, and how stashing works under the hood. We’ll also look at a practical angle for Linux users with dotfiles repos, where local config tweaks are easy to lose.
When and Why to Use Git Stash
Git stash is a shelf for work you aren’t ready to commit. Here’s when it helps and where it bites.
What stashing saves and resets
Running git stash does two jobs at once. It saves your uncommitted changes, then resets your working tree to the last commit so you start clean. Both get tucked away:
- Staged changes: edits you’ve already marked for commit
- Unstaged changes: edits you haven’t marked yet
Each stash sits on a stack, newest on top, so several unfinished jobs can wait at once. The goal is pausing rather than finishing. Your work stays safe.
Everyday situations where stashing helps
Stash shines in moments like these:
- Switching branches mid-edit: you need
main, but unfinished edits block the switch. - Parking one file: one half-done file moves aside while the rest stays put.
- Pausing exploratory edits: you try a risky idea, then return to a known-good state.
- Breaking down large commits: stash the unrelated changes, commit the focused part, then bring the rest back.
- Stashing dotfiles before pulling updates: a Linux user with a dotfiles repo (the git repo holding their config files) has a hand-tuned hyprland bar. They stash the tweaks, pull the update, then reapply the stash so their colors survive.
Where stashes can trip you up
Stashes come with a few traps:
- Local only, not pushed: a stash lives on your machine and isn’t sent along when you push.
- No server backup: if the machine fails and you haven’t backed up the repo, the stash goes with it.
- Easy to forget: an old stash can sit unnoticed for months, quietly holding work you meant to finish.
- Hard to reapply after changes: if the code has moved on, reapplying can produce conflicts you’ll resolve by hand.
Treat a stash as a pause button, not a filing cabinet.
Saving Your Work into a Stash
Sometimes you need to set uncommitted work aside. A stash is git’s shelf for exactly that.
Running the basic stash command
git stash push saves your modified tracked files and resets them to match your last commit. Your edits are saved rather than committed, so your history stays untouched. Think of a Linux user who tweaked waybar in a dotfiles repo and needs to pull updates.
After that, git status shows a clean working tree, so the pull goes through and the waybar edits wait on the shelf.
Bare git stash works too, but push is the form to learn. Is git stash deprecated? It isn’t. Only the save subcommand is, and push replaces it.

Naming a stash so you remember it
Every stash gets a default WIP (work in progress) description. It works for one stash, but it blurs together once you have several.
Pass -m to annotate yours: git stash push -m "waybar: tighten tray spacing". A clear message, ideally with the why, makes git stash list easy to scan when several stashes pile up.
Handling new and ignored files
By default, stash skips untracked files, meaning files git isn’t tracking yet. Untracked config files need -u: if you created hypr/theme.conf and never ran git add, a plain stash leaves it behind. Use -u (or --include-untracked) to stash them too.
Use -a (or --all) to include ignored files, the ones your .gitignore lists. Use it sparingly.
Stashing only part of your changes
Not every change needs to go on the shelf at once. Running git stash push -p walks you through each hunk, a block of changed lines, and asks what to do with it. At each prompt, type:
ystashes this hunknskips itssplits iteedits it by handqquits without deciding on the rest
To stash a single file with a pathspec, pass its path after --: git stash push -- hypr/hyprland.conf. The -- marks what follows as a path, and everything else stays put.
--staged shelves only what you’ve already added with git add. Say your kitty change is staged and your waybar edit isn’t: git stash push --staged takes just the kitty change.
--keep-index works the other way around, stashing unstaged changes while leaving staged ones in place. It’s handy for testing what you’re about to commit.
Checking and Organizing Your Stashes
Here’s how to find the right stash, peek inside, and clean up the rest.
Listing stashes and their numbers
Run git stash list to see every saved stash. Each gets a label like stash@{0}, and the list runs newest first, so stash@{0} is always your latest save.
Git also accepts time-based references like git stash show 'stash@{2 days ago}', quotes included. The lookup works because a reflog logs where the stash has pointed over time.
The numbers describe position, not identity. Drop one stash and everything below it shifts, so re-run git stash list before you act.
Looking inside a stash
Peek before you pop. git stash show prints a diffstat, a short summary of which files changed and how many lines moved. Add -p for the full diff, or -u to include untracked files, meaning files git isn’t tracking yet.
Consider a Linux user with a dotfiles repo who stashed a half-finished hyprland config. On Monday, git stash show -p stash@{1} shows whether it’s the keybind they want or an abandoned experiment, so they apply only what they need.
Removing stashes you no longer need
git stash drop deletes one stash, defaulting to stash@{0}. Pass another name to target it, like git stash drop stash@{1}. The output includes the commit hash, so jot it down if you’re unsure.
git stash clear wipes every stash at once. Cleared entries are hard to recover, so double-check first.
Dropped stashes can still be recovered for a while. Their commits linger as dangling commits (commits nothing points to) until garbage collection, git’s cleanup pass, removes them.
Hunt them down with git fsck --unreachable | grep commit, then restore one with git stash apply <hash>.
Bringing Stashed Work Back
Stashing is the easy half. Getting your work back out is where we tend to get stuck.
Choosing between pop and apply
Both commands restore your saved changes. The difference is what happens afterward:
git stash popapplies the stash, then removes it.git stash applyapplies it and keeps it in the stash stack (your list of saved stashes).
Apply is handy when the same changes belong on several branches. Say you stashed a waybar color tweak in your dotfiles repo on main. You apply it there, then apply it again on waybar-layout.
Both commands default to the latest entry, stash@{0}, so name another, like stash@{2}, to grab an older one.

Keeping your staged changes staged
By default, pop doesn’t restage anything, so everything comes back unstaged. Add --index to restore the staging too: git stash pop --index.
Picture a user who staged only a hyprland keybind file before switching tasks. Plain pop hands it back unstaged, while --index keeps it staged. The restore can fail on conflicts, and git will say so, so read its output before you assume everything’s back.
What is stash & checkout?
Your worktree holds the files on disk right now, edits included. A commit is a snapshot recorded in your branch history. A stash sits between them: a stack of uncommitted work you can park without making a throwaway commit. If terms like worktree and commit are new to you, a Git tutorial covers version control from scratch.
Checkout switches branches, and stash sets your edits aside first. The usual pattern is to stash on one branch, check out the other, and apply the stash there. Git even applies a stash over uncommitted edits, as long as the two don’t touch the same files.
What to do when conflicts appear
If the stash doesn’t apply cleanly, git marks the conflicts and keeps the entry, so you still have it. Fix the marked files, git add them, then run git stash drop once you’re finished.
Want the stashed copy of a file as-is? Run git checkout --theirs <file> and git add it. During a stash apply, --theirs refers to the stashed side.
For example, a Linux user pulls new commits and hits a conflict in ~/.config/waybar/style.css. They want their local palette, so one --theirs checkout and a git add settles it, and their palette survives the pull.
Turn a stash into a new branch
git stash branch <name> creates a new branch at the commit where you made the stash, applies the changes there, and drops the stash on success. Because the branch starts from that original commit, the changes match the code they were written against.
This helps once your branch has diverged. Say you stashed a hyprland keybind experiment, then committed on main for a week. Applying it now means untangling everything in between.
git stash branch hypr-keys gives you a clean base where the tweak slots right in. Clean start, clean apply.
Other Ways to Park Your Work
Stash isn’t the only parking spot, and sometimes cleanup beats parking. Here are the alternatives:
Saving work as a temporary commit
A WIP (work in progress) commit is a temporary commit, not a finished one. Picture a Linux user with a dotfiles repo who gets pulled away mid-edit: they commit the half-done waybar tweaks, fix the urgent bug, and come back later.
- Commit as WIP:
git add -A && git commit -m "WIP" - Undo with reset:
git reset --soft HEAD~1keeps your changes staged. - wip/unwip aliases: define
alias.wipandalias.unwipin~/.gitconfig. - Push for backup:
git push origin HEAD:wip-backupcopies it to your remote.
Beware committing secrets. A WIP commit is still a commit, so a leaked token survives even after you delete it.
Keep secrets out of WIP commits. The alias stages everything, so add files like .env to .gitignore first. Look before you commit.

Splitting big changes into commits with stash
Picture a tinkerer whose working tree mixes hyprland keybinds, a kitty theme swap, and a zsh cleanup. Separate commits make reverting the theme a one-command job.
- Save the end result.
git stashsets the finished version aside. - Apply and trim per commit. Run
git stash apply, thengit add -pto commit one piece at a time. Skipped changes wait for the next commit. - Resolve with restore —theirs. If a conflict appears,
git restore --theirs <file>keeps the stash’s version of that file. Only use it when you’re sure that version is right.
Cleaning up or throwing away changes
Plain git stash skips untracked files, so new scratch files stay put. git clean deletes them for good. Gone means gone.
- Dry run first:
git clean -ndlists what would go without deleting anything. Check the list before runninggit clean -fd. - Stash —all as the safer option:
git stash push --allalso saves untracked and ignored files. - Discard local changes:
git restore .throws away unstaged edits. Git keeps no copy, so stash first if you might want them.
Other tools for datasets and reproducibility
- DVC for large datasets: DVC (Data Version Control) keeps big data out of git’s history but still tracks its versions.
- Reproducible environments: commit a file that pins exact package versions.
- Commits for publication results: commit the exact code behind your numbers and tag it.
A student rerunning their analysis on a new laptop can start from exactly the state behind their published numbers.
How Stashing Works Under the Hood
Stashing feels like a hidden drawer inside Git, but it’s built from the same parts as everything else. A few facts make its behavior predictable.
Stashes are saved as commits
A stash isn’t a special file format. Git saves it as a commit, the same kind of object your normal history uses, so you can inspect it with the tools you already know. Here’s what happens when you run git stash:
- refs/stash and reflog.
refs/stashpoints at your newest stash, and its reflog (a record of where a ref has pointed over time) keeps older ones reachable asstash@{1},stash@{2}, and so on. - Two or three commits. A plain stash creates two: one for your working tree and one for what’s staged in the index.
- Third parent for untracked files. With
-u, the stash commit gets a third parent that holds your untracked files.
What popping changes and cleans up
Think of a Linux user with a dotfiles repo full of hyprland and waybar tweaks who needs an upstream fix. They run git stash, pull, then git stash pop, and their tweaks return on top of the new code. Popping changes your files, not your history.
Pop updates your working tree and index as it restores the saved changes. Add --index if you want staged changes to come back staged, not just as edits.
Your tweaks are back. The stash commits are a different story.
Once a stash is popped, nothing references its commits, so they await garbage collection, Git’s cleanup step for objects no ref can reach.
Stashing is one of those small Git habits that pays off the first time you need it. You can switch tasks without committing half-finished work, and you can come back to it without guessing where it went.
Keep your shelf tidy, check what’s in it before you reapply, and treat conflicts as a normal step rather than a disaster. Your dotfiles deserve that care too.
Your half-finished work deserves a safe place to wait, and now you know exactly where to find it.
Questions
What is a git stash?
A Git stash temporarily saves uncommitted changes, including staged and unstaged edits, and resets the working tree to the last commit. Stashes are kept on a local stack so you can apply or pop them later without adding a commit to your project history.
What is stash & checkout?
“Stash and checkout” means saving your uncommitted changes with `git stash`, then switching branches with `git checkout`. You can later apply or pop the stash on the branch where you want to continue working.


