# Git Stash: set aside uncommitted work

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-stash-full-en
`git stash` saves tracked changes on a stack and restores a clean working tree. `git stash pop` reapplies the newest entry and drops it.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-59-A, TE-59-B and TE-59-C. The expected non-zero exit is TE-59-C (exit status 1). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

### TE-59-A: stash cleans the tracked working tree and pop restores the change

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt
```

Command:

```bash
git stash >/dev/null; echo clean=$(git status --porcelain | wc -l); echo list_before=$(git stash list | wc -l); git stash pop >/dev/null; echo list_after=$(git stash list | wc -l); echo restored=$(git status --porcelain | wc -l); cat f.txt
```

Recorded output:

```
clean=0
list_before=1
list_after=0
restored=1
one
two
```

Exit status: 0. The output matches the expected text written before the run.

### TE-59-B: git stash push -m saves the change under a message that git stash list shows

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
printf 'two\n' >> f.txt
```

Command:

```bash
git stash push -q -m wip; git stash list
```

Recorded output:

```
stash@{0}: On main: wip
```

Exit status: 0. This status and the output match what was written before the run.

### TE-59-C: expected non-zero exit: git stash pop with an empty stash list stops with exit status 1

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'one\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git stash pop
```

Recorded output: none, standard output was empty.

Standard error from the same run:

```
No stash entries found.
```

Exit status: 1. This status and the output match what was written before the run.

TE-59-B: by the setup, f.txt has an unstaged change. git stash push -m wip saved it, and git stash list printed one entry, stash@{0}: On main: wip. TE-59-C: by the setup, nothing was stashed. git stash pop exited with status 1 and printed No stash entries found. to standard error.

## Limits

TE-59-A and TE-59-B cover an unstaged change to a tracked file, and TE-59-C covers an empty stash. Untracked files, staged changes and stash conflicts on pop were not tested. Not tested on this page: the subcommands `show`, `drop`, `apply`, `branch` and `clear`, the `--index` option of `pop`, and the options of `push`: `-p` or `--patch`, `-k` or `--keep-index`, `-u` or `--include-untracked`, `-a` or `--all`, and `--pathspec-from-file` with `--pathspec-file-nul`. The usage text printed by `git stash -h` in git 2.34.1 lists them. No `git stash` command here used them.

## Source

- https://git-scm.com/docs/git-stash

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-59-A` | stash cleans the tracked working tree and pop restores the change | 0 | PASS | `77a379f0397b` |
| `TE-59-B` | git stash push -m saves the change under a message that git stash list shows | 0 | PASS | `6cf540b5aec0` |
| `TE-59-C` | expected non-zero exit: git stash pop with an empty stash list stops with exit status 1 | 1 | PASS | `b014757852b8` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git Blame: who last changed each line](https://kairos-2z6s.onrender.com/res/git-blame-full-en)
- [git remote: connect a repository to another one](https://kairos-2z6s.onrender.com/res/git-remote-full-en)
- [Git Stash Include Untracked: set aside new files too](https://kairos-2z6s.onrender.com/res/git-stash-include-untracked-full-en)
- [Git Show: read one commit](https://kairos-2z6s.onrender.com/res/git-show-full-en)
- [Git Shortlog: commits per author](https://kairos-2z6s.onrender.com/res/git-shortlog-full-en)
