Git 2 reference · Undoing Changes
git stash Command (Git)
Save uncommitted changes temporarily, switch tasks, then reapply them with pop or apply.
Git 2
Syntax
git stash [push -m MSG] [-u] git stash list|pop|apply|drop
Parameters
| Parameter | Description |
|---|---|
push -m MSG |
Stash with a description. |
-u |
Include untracked files. |
pop |
Reapply and remove the latest stash. |
apply stash@{N} |
Reapply without removing. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo wip >> README.md
git stash push -q -m 'half-done header'
git status -s | wc -l
git stash list
git stash pop -q; git status -s
Output
0
stash@{0}: On main: half-done header
M README.mdRun this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
echo new > new.txt
git stash -q; ls new.txt 2>/dev/null || echo 'untracked file not stashed'
git stash push -q -u; ls new.txt 2>/dev/null || echo 'stashed with -u'
Output
new.txt stashed with -u
Run this on your computer — see “Get Started” for setup.
Related
git switch· Switch to another branch, or create one and switch to it with -c; the modern replacement for git checkout branches.git restore· Discard working-tree changes to files, or unstage files, without touching other work.- Stashing Work in Progress · tutorial