Sikau

Git & GitHub · Day 10 · about 20 min

Stash: put work aside

Pause half-done work to fix something urgent.

Urgent bug, messy desk

You're halfway through a new menu design when the boss shouts: the phone number on the home page is wrong! Your changes aren't ready to commit. stash them, fix the bug, then pick up where you left off.

stash and pop

echo "<h1>Menu (new design)</h1>" > menu.html
git status
git stash
git status
echo "<h1>Himalayan Café</h1><p>Call 01-555</p>" > index.html
git commit -am "Fix phone number"
git stash pop
cat menu.html
  • git stash list shows the shelf; git stash -u includes untracked files too.
  • Stashes are local and easy to forget — prefer a quick commit on a branch for anything longer than a few minutes.

The rest of this lesson

  • How the stash worksexplain
  • Stash or commit?explain
  • After git stashpredict
  • Untracked filepredict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 18 lessons of Git & GitHub