Save your work with Git Stash

Sam Lim
2 min readJul 1, 2021

Have you ever encounter a situation that your boss coming to your desk, asking are you free or not? But your boss doesn’t care about the answer, when he or she asking this question, it means to stop whatever you’re doing and get this done for me now!

So now you have to save your task and switch focus. But how you do it? Stage and commit with messages like “I’ll be back”. Then start a new hotfix or feature and start development.

Credited to https://giphy.com/

But it is not a proper way of how you do it, as it has committed and make confused the git model of your project. What should you do to save incomplete work then? Here’s come the cavalry — Git Stash.

# Save / Stash your work
git stash

Step 1 : Change directory to your project

cd ~/path_to_your_project

Step 2 : Save your work

git stash

Then you’re free to proceed with anything you wanna do.

After you have done the urgent task, just come back to wherever you left and use this command:

# Restore most recent stashed changes & delete it
git stash pop

That’s it! There is more useful git stash related feature you can use as well.

# List all stashed changes
git stash list
# Restore most recent stashed changes & keep it
git stash apply
# Clear all stash
git stash clear
# Stash with desired message
git stash save "message_description"
# Select stash you want to restore after list stash
git stash stash@{1}

Conclusion: Git Stash is the proper way used to save our work instead of stage and commit with a meaningless message. Do start practice with it. Happy coding!

--

--

Sam Lim

Hi guys, I’m Sam from Malaysia. I start my career as a web developer since 2017. Major in PHP, NodeJS, Javascript. I had experience with Flutter, AWS as well.