Learn How to Git Stash When You Working on Git
I wrote this tutorial about how to use the Git Stash feature and how it can ease your life as a software developer.
What is Git Stash?
Git stash allows you to save a snapshot of your code without committing it to the branch.
git stash
When to use it?
When you have changes in your local code and want to save them without committing to your branch.
Remember that time you wrote a bunch of code and after some time realized you were in the wrong branch?
With Git Stash, you can quickly transfer your code to another branch.
How to use it?
Save your changes with a message.
git stash save "Your beautiful stash message"
Write this command in your terminal to see your list of stashes:
git stash list
stash@{0}: Your beautiful stash message
stash@{1}: Other stash
stash@{3}: That's it
Show the full diff of the code from the stash.
git stash show -p
Drop a specific stash.
git stash drop stash@{1}
Apply your last stash and discard it.
git stash pop
Apply your last stash and keep it for possible later use.
git stash apply
Apply stash number 1.
git stash apply stash@{1}
Show the files the stash touches
git stash show
Create a branch from the stash
git stash branch <name> stash@{1}
Conclusion
Happy coding