Lesson Completion
Back to course

Module 07: Stashing and Cleaning

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 pop vs git stash apply
  • Use git clean to 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 stash and messages

7.3 Listing Stashes

  • git stash list

7.4 Applying Stashes

  • git stash apply vs git stash pop

7.5 Dropping and Clearing Stashes

  • git stash drop and git 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

  1. Create a stash, list it, and apply it.
  2. Stash changes with a message and pop it.
  3. Stash untracked files with -u.
  4. Run a safe clean with git clean -n.
  5. Clear all stashes.

Key Takeaways

  • Stash is for temporary storage, not long-term.
  • apply keeps the stash; pop removes it.
  • git clean removes 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).