0/5

Lesson06

intermediate

Shelve Work with git stash

Goal

Put unfinished work aside, switch branches, and bring the work back later.

You are halfway through a profile page on feature/profile when someone asks you to check something on main. Your edit to profile.js is not ready to commit, and main has a different version of that file, so Git will not let you switch.

Shelve the work, visit main, come back, and pick up exactly where you were.

Objectives

0/5
  1. Your unfinished work is in the stash. (Current objective)
  2. You are on main. (Not started)
  3. You are back on feature/profile. (Not started)
  4. profile.js has your unfinished edit again. (Not started)
  5. The stash is empty again. (Not started)

Your task nowStep 1 of 5

Your unfinished work is in the stash.

Need help?

Reference

Shelving work

$ git stash

Saved working directory and index state WIP on feature/profile: 1a2b3c4 Add profile page

Your uncommitted changes are saved in a stash entry and the files go back to the last commit, so switching branches is safe again. Untracked files stay put unless you add -u.

Getting work back

git stash pop

  • Reapplies the newest entry
  • Removes it from the stash list

git stash apply

  • Reapplies the newest entry
  • Keeps it in the list (drop it later with git stash drop)

Preparing your workspace…

Repository Graph

Click a commit to inspect it

0 commits

Working Tree

Not a Git repository yet

No unstaged changes

Your working tree matches the staging area.

Staging Area

Files prepared for the next commit

No staged changes

Use git add to prepare files for your next commit.

Repository

Committed history

No commits yet

Use git commit to record staged changes.