DEV Community

Cover image for Usage of git stash
Alestor Aldous
Alestor Aldous

Posted on

Usage of git stash

So Whats The Matter ?

from somewhere in the internet
intro

Will It ?

Imagine this, you were working on some feature that hasn’t been completed and something important came up and you dont want to commit this partial feature with that urgent feature that you added and during this situations, there are a few options :

Horrible one

Reset all the changes and clean out un-tracked stuff


git reset HEAD --hard
git clean -fd

You can do this if there isn’t much that you have done since the last commit. But if you ve spent hours working on it and you are about to complete that? Not a good idea then.

The Correct Way :

You should use git-stash

git stash
Just consider it like a clipboard, running this command will move all your changes to stash. After that you can start working upon that urgent feature, commit that and once you are ready to start working upon that partial feature that you were working upon back at the point when you had to stash the changes, you can get your stashed changes back to your working copy by :

git stash apply

You can clear your stash by using :

git stash -u

and no it will not stash your untracked file

for stashing untracked files you need to run :
To stash untracked files as well, you need to do

git stash -u

Time for some meme's

from multiple sources :
1st
2nd
3rd
4th

commit your thoughts in the comment section

# Conclusion

Keep Coding !!!

🙏 Share with your friends on Twitter

Top comments (1)

Collapse
 
jessekphillips profile image
Jesse Phillips

I find git stash is best used to move changes to another branch, as it will handle merge conflicts. Though there is autostash for that. Anything else seem to get me in trouble.

You shouldn't be afraid to partial commit git has --amend and --fixup for that.

Also I came across an article about working tree to make a clone of the repo in another directory.