You’re working, some priority comes up, but you’re not ready to make a commit yet, and you need to switch branches. What do you do? 🤔

Some people like to make a throwaway commit just to save the work so they can undo it later, but I prefer git stash.

Think of it like a stack. You take the changes you made, bundle them up, save them locally, and then your working directory goes back to a clean state.

Each bundle is a stash and it gets saved on index zero.

You can then switch branches, do whatever you need to do, and when you come back, you can pop or apply the stash, and your most recent changes go back to where they were.

One heads up though: if you have new files that git isn’t tracking yet, they won’t be automatically added to this stash. So before you make a stash with new files, you need to stage them first. 😅

Want the full breakdown on git stash? I covered it in more depth here: Using git stash: pop, apply, and drop

If you want more git tips that save your work, follow along!