Ever get interrupted while coding and need to switch branches fast? Don't worry, Git stash got your back!
Instead of losing your progress or committing half-finished code, just stash it!
Run:
git stash
Your uncommitted work disappears, saved for later. Now you’re free to switch branches!
Once you’re done and ready to continue, bring your work back with:
git stash apply
It will retrieve your most recent stash.
Use git stash list to see a history of all your stashes. You can stash as many times as you need!
git stash list
Want to apply a specific stash? Use git stash apply stash@{0} or any other number from the list.
stash apply stash@{0}
After applying the stash, it still stays in your list! To fully clean up and delete the stash after you’ve applied it, run:
git stash drop
Now it’s truly gone. Nice and tidy!
Pro tip: You can combine both commands with git stash pop to apply and drop the stash in one go!
git stash pop