git stash changes |Video upload date:  · Duration: PT6M33S  · Language: EN

Quick guide to save list apply and manage uncommitted changes with git stash for safe context switching and tidy commits

Why stash exists and why you will love it when you forget to commit

Git stash is the polite way to shove unfinished work into a drawer when you need to switch tasks fast. It saves uncommitted changes so you can check out another branch without committing half finished code that will haunt your commit history forever. Yes it is slightly magical and yes you will use it when a bug needs fixing right now.

Save work fast

Use git stash push -m 'WIP' to save a snapshot and add a short message so future you knows what that mess was about. If you have new files that are not tracked use the -u flag to include them.

git stash push -m 'WIP: experiment with widget' -u

That command parks your modifications and gives you back a clean working tree. Go fix the urgent bug and bask in the illusion of order.

See what you parked

When you forget what you stashed do not panic. Run git stash list to see entries. Peek into an entry with git stash show -p stash@{0} so you do not accidentally reapply someone else's chaos.

Bring changes back or move them to a proper branch

Two common moves when you are done with your context switch are apply and pop. Use git stash apply stash@{0} if you want to keep the stash for later. Use git stash pop if you want to apply the changes and throw the stash away in one go. Conflicts can happen and you resolve them like any merge conflict. Yes it is annoying but it works.

Rescue an experiment into a branch

If the stash deserves a life of its own use git stash branch new-branch stash@{0}. That creates a branch from the commit where you stashed and applies the changes so your experiment can graduate into proper history.

Cleaning up the stash list

Stashes are cheap but hoarding is not a good look. Remove a single stash with git stash drop stash@{0}. If you really want to purge the junk use git stash clear and accept responsibility for what you are deleting.

Quick reference list

  • git stash push -m 'msg' -u Save changes and untracked files
  • git stash list See saved entries
  • git stash show -p stash@{n} Inspect a stash
  • git stash apply stash@{n} Reapply but keep the stash
  • git stash pop Reapply and remove the stash
  • git stash branch name stash@{n} Create a branch from a stash
  • git stash drop stash@{n} Remove one stash
  • git stash clear Remove all stashes

Pro tips that make you look like you know what you are doing

  • Use meaningful messages with -m so stashes are searchable
  • Prefer git stash branch when the work should be an actual branch
  • Inspect with git stash show -p before applying to avoid surprises

Stashing is not a substitute for good commits and clean branches but it is a lifesaver for quick context switches. Use it, name your stashes, and stop committing half finished junk just to switch tasks. Your git history will thank you and your teammates will pretend to be impressed.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.