Video

What Is Git Stash? Save Uncommitted Changes and Switch Branches Safely

Ever needed to switch Git branches while your work is still unfinished?

Git Stash lets you temporarily save uncommitted changes, clean your working directory, and restore your work later.

In this video, we'll explore:
- What Git Stash is and why developers use it.
- How to save and restore uncommitted changes.
- The difference between `git stash apply` and `git stash pop`.
- How to use Git Stash in a Ruby on Rails project.
- Benefits, limitations, and common commands.

The example runs end to end: you're mid-way through a payment feature on feature/payments when an urgent production bug lands. Git refuses the branch switch because your local changes would be overwritten, and neither committing half-finished code nor copying files by hand is a good answer. Stash is.

A few things worth being precise about. Stash saves changes to tracked files by default, both staged and unstaged — untracked files are left behind unless you pass -u, and ignored files need -a. Stash entries live in a stack with the newest on top. `git stash apply` restores the changes and keeps the entry; `git stash pop` restores it and removes the entry, but only if the application succeeded — on conflict the entry is kept so you don't lose it. And stash is local temporary storage, not a backup and not a substitute for commits or a remote branch.

CHAPTERS
00:00 — The Hook
00:10 — The Problem
00:25 — What Is Git Stash?
00:40 — How It Works
01:00 — Practical Git Commands
01:25 — Benefits and Trade-offs
01:45 — The Takeaway


Watch on YouTube

Back to videos