MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Shelving Changes Temporarily with git stash (save, pop, apply, drop)0%
Study Materials
Git & GitHub BasicsProgress 0%
1.1What is Version Control? (Local, Centralized vs Distributed VCS)1.2Why Git? History, Architecture & Core Benefits1.3The Three Trees: Working Directory, Staging Area & Git Repository1.4Installing Git and Initial Configuration (git config user.name / email)
7.1Shelving Changes Temporarily with git stash (save, pop, apply, drop)7.2Undoing Changes Safely: git restore, git reset, and git revert7.3Rebasing Branches: Linear History with git rebase vs git merge7.4Tagging Milestones and Software Releases with git tag
HomeTutorialsGit & GitHub BasicsShelving Changes Temporarily with git stash (save, pop, apply, drop)
Undoing Changes Safely: git restore, git reset, and git revert

Shelving Changes Temporarily with git stash (save, pop, apply, drop)

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Software development is full of interruptions: you are deep in the middle of writing an unfinished feature when an urgent production bug alert arrives. Your current code is broken and half-written—you can't commit it, but you also can't lose it. The git stash command is your temporary clipboard.


1. How Git Stash Works

git stash takes the dirty state of your working directory (all modified tracked files and staged changes) and saves it onto an internal stack of unfinished changes, returning your working directory to a clean HEAD state!

1[ Working Directory: Broken, half-finished code ]
2 |
3 git stash
4 |
5 v
6[ Stash Stack ] <------------------ [ Clean Working Directory ]
7 stash@{0}: WIP on feature-cart (Ready to switch branches & fix bug!)

2. Core Stash Commands

A. Stashing Your Changes

1# Quick stash
2git stash
3 
4# Stash with a descriptive message (Recommended!)
5git stash push -m "WIP: half-implemented payment modal"

B. Including Untracked Files (-u)

By default, git stash only stashes tracked files. If you created brand new files that haven't been committed before, add the -u (or --include-untracked) flag:

1git stash -u

3. Inspecting and Restoring Stashes

A. View All Saved Stashes (git stash list)

1git stash list

Output:

1stash@{0}: On feature-cart: WIP: half-implemented payment modal
2stash@{1}: On main: WIP: temporary database connection string

B. Restoring Changes: git stash pop vs. git stash apply

CommandRestores Changes to Working Tree?Removes Stash from Stack?
git stash popYesYes (deletes the stash item if no conflicts occur)
git stash applyYesNo (leaves the stash on the stack so you can reuse it elsewhere)
1# Apply most recent stash and remove it from stack
2git stash pop
3 
4# Apply a specific older stash by index without removing it
5git stash apply stash@{1}

4. Cleaning Up Stashes

Stashes accumulate over time and consume disk space. Clean them up regularly:

1# 1. Drop a specific stash from the stack
2git stash drop stash@{0}
3 
4# 2. Clear ALL stashes completely (irreversible!)
5git stash clear

5. Typical Real-World Scenario

  1. 1
    Working on feature-redesign, edited 3 files. Code doesn't compile yet.
  2. 2
    Manager asks for urgent hotfix on main.
  3. 3
    You stash: git stash push -m "WIP redesign".
  4. 4
    Switch to main: git switch main.
  5. 5
    Fix bug, commit, and push: git commit -am "fix: hotfix security header" -> git push.
  6. 6
    Switch back: git switch feature-redesign.
  7. 7
    Restore your work: git stash pop.
  8. 8
    Continue coding right where you left off!

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does git stash do?
Question 2
Why does git stash ignore newly created untracked files by default?
Question 3
What is the primary difference between git stash pop and git stash apply?
Question 4
Which command lists all stashes currently stored in the repository?
Question 5
How can you discard and delete all stashed entries from your repository completely?
Next Lesson

Undoing Changes Safely: git restore, git reset, and git revert

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Syncing Upstream Repositories and Keeping Forks UpdatedUndoing Changes Safely: git restore, git reset, and git revert

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Git & GitHub Basics with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext