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.
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.
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.
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.
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.
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.
git stash push -m 'msg' -u
Save changes and untracked filesgit stash list
See saved entriesgit stash show -p stash@{n}
Inspect a stashgit stash apply stash@{n}
Reapply but keep the stashgit stash pop
Reapply and remove the stashgit stash branch name stash@{n}
Create a branch from a stashgit stash drop stash@{n}
Remove one stashgit stash clear
Remove all stashes-m
so stashes are searchablegit stash branch
when the work should be an actual branchgit stash show -p
before applying to avoid surprisesStashing 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.