ProgramGuru

Temporarily set aside work with git stash

Temporarily set aside work with git stash

You are halfway through a feature when an urgent fix arrives. The work is not ready for a commit, but you need a clean working tree to switch context.

What you’ll learn

  • Create a named stash.
  • Inspect and reapply stashed work.
  • Explain when stash is appropriate.

Pause a dirty working tree

  1. WIP

    You have incomplete local edits.

    dirty tree
  2. Stash

    Store the state temporarily.

    stash@{0}
  3. Resume

    Reapply it later.

    apply / pop
apply / pop

A stash is temporary local storage for unfinished state

git stash push saves selected working state so you can return to a cleaner checkout. git stash list shows saved entries. git stash apply reapplies one while keeping it; git stash pop applies and then removes it if successful.

By default, untracked files are not always included; use options such as -u deliberately when needed. A stash can also conflict when reapplied if the target files changed meanwhile.

Pause and resume unfinished changes

Run this in a disposable practice repository unless the lesson explicitly says otherwise.

git stash push -m "WIP search layout"
git stash list
# switch and handle another task
git stash show -p stash@{0}
git stash pop

The message makes the stash easier to identify. show -p lets you inspect what you saved before reapplying it.

Practice: Stash unfinished work

Your task: Create a staged change and an unstaged change, stash them, verify the working tree is clean, then pop the stash and confirm both return.

Common pitfall to avoid

Do not use the stash as long-term project history. Important work should eventually become named branches and commits that are easier to discover and share.

Check your understanding

What is the practical difference between stash apply and stash pop?
Choose one answer. You can try again.

Answer and explanation

apply normally keeps the stash entry; pop attempts to remove it after applying.

Correct.

Stash unfinished work: what to remember

Temporarily set aside work with git stash is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.

Read further: official supporting documentation.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Mark important commits with tags →