Skip to main content
v2026.11,986 entries · CC-BY 4.0

Stashing Changes in Git: push, pop, apply and list

How to stash changes in Git: push with a label, include untracked files, pop vs apply, fix conflicts, and what a stash does not save.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

Git stash saves your uncommitted work on a stack and returns the working tree to the last commit, so you can switch branches and come back. Per the Pro Git book, stashing “takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).” The command to save is git stash push; the commands to bring work back are git stash pop and git stash apply. The part most guides skip, covered below, is what a stash does not save and what happens when applying it hits a conflict.

What stashing is used for in research

Analysis code changes constantly while a paper, thesis or grant deliverable is in progress. Stashing fits three recurring situations:

  • Switching branches mid-edit. You are halfway through changing a model script and need to rerun the version on another branch. Stash, switch, rerun, switch back, pop.
  • Setting aside one file. A pathspec limits the stash to the files you name, so a half-finished data-cleaning script can be parked while the rest of the tree stays as it is.
  • Pausing exploratory edits. Work you are not ready to commit stays recoverable instead of being overwritten. For the opposite goal, throwing changes away, see how to discard local changes in Git.

Stashing is a local convenience, not a record of your work. Results that a publication depends on belong in commits; see computational reproducibility for why a recoverable, labelled history matters.

Install or access

git stash is part of Git itself, so there is nothing extra to install. Git is distributed from the official site, git-scm.com, which also hosts the command reference (git-stash) and the free Pro Git book. Run the commands below inside a Git repository.

Step-by-step: stash and restore your work

The synopsis in the official manual is git stash [push] [-p|--patch] [-S|--staged] [-k|--[no-]keep-index] [-q] [-u|--include-untracked] [-a|--all] [(-m|--message) <message>] [--pathspec-from-file=<file>] [--] [<pathspec>...].

  1. Save your changes with a label. Run git stash push -m "describe the work". Per the manual, push saves “your local modifications to a new stash entry and roll[s] them back to HEAD”; -m adds an optional description.
  2. Include untracked files if you need them. By default only modified and staged tracked files are stashed (Pro Git). Add -u (--include-untracked) to also stash untracked files; they are “cleaned up with git clean”. Add -a (--all) to include ignored files as well.
  3. Stash only some files. Name them after the options: git stash push -m "wip cleaning" -- scripts/clean.R. The manual states the new entry “records the modified states only for the files that match the pathspec.”
  4. Stash only part of a file or only staged changes. -p (--patch) lets you choose hunks interactively; -S (--staged) stashes only what is currently staged. If both are given, --patch takes priority.
  5. List your stashes. Run git stash list.
  6. Look inside one. Run git stash show for a diffstat of the latest entry, or name one: git stash show stash@{1}. Add -u to include untracked files in the display (config stash.showIncludeUntracked defaults to false).
  7. Bring the work back. Either git stash pop (apply it, then remove it from the list) or git stash apply (apply it and keep it on the stack). Pro Git: “The apply option only tries to apply the stashed work — you continue to have it on your stack.”
  8. Restore staged state too. Add --index to pop or apply to reinstate the index changes as well as the working tree; the manual notes this can fail on conflicts. The config stash.index defaults to false.
  9. Remove entries. git stash drop removes one; git stash clear removes all. The manual warns that cleared entries “may be impossible to recover”, so only clear once you are sure.

The old form git stash save is deprecated “in favour of git stash push” in the manual, and save cannot take a pathspec.

Output and how to read it

Each entry in git stash list looks like the manual’s example:

stash@{0}: WIP on submit: 6ebd0e2... Update git-stash documentation
  • stash@{0} is the entry name. stash@{0} is the newest, stash@{1} the one before it. A bare integer n means stash@{n}, and no argument means stash@{0}.
  • Time syntax also works, for example stash@{2.hours.ago}.
  • WIP on submit is the branch the stash was made on, followed by the commit it started from. A label from -m replaces the generic text, which is why labelling helps once you have several entries.
  • After git stash drop or a successful pop, Git prints a line in the form Dropped stash@{0} (364e91f3...) as shown in Pro Git.

Troubleshooting

Why did pop fail with a conflict, and is my stash gone?

No. The manual states that applying a stash can fail with conflicts, and in that case “it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards.” apply, pop and branch exit with status 1 on conflicts and leave the entry in place.

Why are my new data files missing from the stash?

Untracked files are not stashed unless you pass -u, and ignored files (large outputs, for instance) are not stashed unless you pass -a. Check with git stash show -u before you rely on an entry.

How do I stash a single file?

Use a pathspec after --, as in step 3 above.

How do I get the stash onto its own branch?

git stash branch <branchname> [<stash>] creates and checks out a new branch starting from the commit where the stash was created, reapplies the work, and drops the stash if that succeeds. It is the route when the branch you stashed on has moved on and pop conflicts.

Did I apply the wrong stash?

Run git stash list and name the entry explicitly, for example git stash apply stash@{2}. Use apply rather than pop when you are unsure, because it keeps the entry.

Free alternatives and when to use each

Git is free, and so is every option below; they differ in how much they keep and where.

Option What it does Source
git stash push then pop Saves tracked changes on the stack and removes them from the tree; pop applies and removes the entry. git-scm.com git-stash; Pro Git
git stash apply Applies the entry and keeps it on the stack. git-scm.com git-stash; Pro Git
git stash branch Turns a stash into a new branch from its original commit, dropping the stash on success. git-scm.com git-stash; Pro Git
git stash push -- <pathspec> Records only the files that match the pathspec. git-scm.com git-stash
Discard instead of save Throws the changes away rather than keeping them; see discarding local changes in Git. CASRAI guide

For versioning large datasets alongside code, stashing is not the tool; see DVC data version control for research datasets. A related habit for sharing a working setup is covered in sharing a reproducible conda environment.

FAQ

What is the difference between git stash pop and git stash apply?

pop applies the stashed state and removes it from the stash list. apply applies it and leaves it on the list. If either hits conflicts, the entry stays in place.

How do I stash untracked files?

Add -u (--include-untracked) to git stash push; add -a (--all) to include ignored files too.

How do I stash a single file?

Run git stash push -- path/to/file. Only files matching the pathspec are recorded in the entry.

How do I see what is in a stash?

Run git stash show (latest) or git stash show stash@{n}. The default is a diffstat; -u includes untracked files.

Can I stash on one branch and apply on another?

Yes. Pro Git says a stash can be reapplied “even on a different branch”.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Stashing Changes in Git: push, pop, apply and list

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →