Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git stash: set aside your changes

Need to switch branches but haven't finished your work? git stash temporarily saves your changes so you can come back to them later.

When to use git stash?

Switching branches

You're working on a feature but are asked to fix an urgent bug on main. Stash your changes, switch branches, fix the bug, then come back.

Before a pull

You have local changes and git pull refuses to merge. Stash, pull, then pop to get your changes back on the updated version.

Testing something

You want to quickly test a clean state of the code without losing your work in progress. Stash, test, then pop.

Git stash in practice

Set aside and retrieve your changes.

Stashing changes

Retrieve and manage

Essential stash commands

git stash

Stash changes (shortcut for push)

git stash push -m "msg"

Stash with a descriptive message

git stash list

List all saved stashes

git stash pop

Restore and remove the latest stash

git stash apply

Restore without removing the stash

git stash drop stash@{n}

Remove a specific stash

Part of the Undo Changes in Git guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git stash

Practice stash in GitQuest

GitQuest investigations put you in situations where you need to juggle between branches and changes.

Start practicing now