Overview
This module covers how to temporarily save work, clean your working directory, and switch contexts safely.
Learning Objectives
- Understand what stashing is and when to use it
- Create, list, and apply stashes
- Drop and clear stashes safely
- Use
git stash popvsgit stash apply - Use
git cleanto remove untracked files - Recover from common stash mistakes
- Use stash with untracked files
Topics Covered
7.1 What is Stash?
- Why stash exists
7.2 Creating a Stash
git stashand messages
7.3 Listing Stashes
git stash list
7.4 Applying Stashes
git stash applyvsgit stash pop
7.5 Dropping and Clearing Stashes
git stash dropandgit stash clear
7.6 Stashing Untracked Files
git stash -u
7.7 Using git clean
- Safe clean with
-n
7.8 Recovering from Stash Mistakes
- Finding stashes in reflog
7.9 Stash Best Practices
- Small stashes, clear messages
7.10 Cleaning Best Practices
- Avoid deleting needed files
Hands-on Exercises
- Create a stash, list it, and apply it.
- Stash changes with a message and pop it.
- Stash untracked files with
-u. - Run a safe clean with
git clean -n. - Clear all stashes.
Key Takeaways
- Stash is for temporary storage, not long-term.
applykeeps the stash;popremoves it.git cleanremoves untracked files, use it carefully.
Additional Resources
- Pro Git: Git Stashing
git help stash
Assessment
- Quiz on stash and clean commands
- Practical: stash, apply, clean, and recover
Next Module
Module 08 will cover rewriting history (reset, revert, rebase).