Git 2 reference · Undoing Changes

git stash Command (Git)

Save uncommitted changes temporarily, switch tasks, then reapply them with pop or apply.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git stash [push -m MSG] [-u]   git stash list|pop|apply|drop

Parameters

ParameterDescription
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

Stash and pop
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.md

Run this on your computer — see “Get Started” for setup.

Untracked files need -u
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.

Was this page helpful?