Last Updated: February 25, 2016
·
475
· klj613

What are git stashes really?

Git stashes are actually just commits in the local git repository.

I use git stashes a lot to back up my current un-commited code (git stash, git stash apply) so I can always revert back.

I see one problem with git stashes... They are only on your machine. There are actually no backups.

At the end of the day I do this..

git add .
git commit -m "stash"
git push origin [branch-name]

and in the morning...

git reset HEAD~1

I also do this when I want to switch branches and I want to save my current unfinished work. Therefore I know easily this "peice of work" belongs to this branch.

git add .
git commit -m "stash"
git push origin feature-y
git checkout feature-x
#do work
git checkout feature-y
git reset HEAD~1