WeCodeAcademy

Shelving Work with git stash

You are halfway through a change and need a clean folder, for example to switch branches. git stash puts your unfinished work on a shelf and restores the last commit. Later, git stash pop brings it back.

Examplebash
Open in editor »
/ $

Your edit is safe on the shelf. See what is stored, then get it back.

Examplebash
Open in editor »
/ $

git stash pop restores the work and removes it from the shelf. git stash apply restores it and keeps a copy. git stash drop deletes the newest entry, and git stash -m "message" gives an entry a name. Stash only saves changes to files Git already tracks, not brand new untracked files.

Quick check

What does `git stash pop` do?

Your turn: write the code

app.txt is committed, then edited. Shelve the edit with git stash, then print how many entries git stash list shows.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.