Get to know about git stash and keep calm

Abdullah Al Mamun
2 min readMar 22, 2023

--

Remember when you made some changes and you need to pull now, Meet git stash

Photo by Yancy Min on Unsplash

Git stash is a handy command that allows you to temporarily save changes that are not yet ready to be committed. This is useful if you need to switch to a different branch or work on a different feature, but you don’t want to commit your changes yet.

git stash save "message"

git stash list

git stash apply

git stash drop

git stash pop

Here’s how to use Git stash:

1. Make some changes to your files.

2. Check the status of your repository using

git status

3. Run git stash save "message" to stash your changes. The "message" part is optional but recommended, as it helps you identify what changes you stashed later on.

4. Run git status again to see that your working directory is now clean.

5. Switch to a different branch or work on a different feature.

6. When you’re ready to retrieve your stashed changes, run git stash list to see a list of all stashes you've created.

7. Run git stash apply to retrieve the most recent stash, or git stash apply stash@{n} to retrieve a specific stash by number.

8. If you’re happy with the changes you’ve retrieved, you can delete the stash using git stash drop, or you can apply it to your working directory and delete it at the same time using git stash pop.

Photo by Paweł Adamczak janusze_zycia on Unsplash

And that’s it! Git stash is a simple yet powerful command that can help you manage your changes more effectively.

--

--

Abdullah Al Mamun

Software engineer, Love to write clean, readable and reusable code. Data Science enthusiast