Image from Wikimedia Commons

How to Save Temporary Changes in Git Using Git Stash

Table of Contents

Git stashing is a way to temporarily save changes that you do not want to commit yet. This is useful if you need to switch branches, but do not want to commit your changes first.

Stash your Changes in Git

To stash your changes, type:

git stash
git stash push -m "description of stash"

Once you are done, you can reapply your stash with:

git stash apply
git stash apply 2  # 2nd item in previous list
git stash apply stash@{2}

Listing your Stash

To show your stored stashes, type:

git stash list

Cleaning up the Stash

Reaply stash and remove it from stash with:

git stash pop 2

If you want to remove a stash, type:

git stash drop 2

Finally, to remove all items from stash, type:

git stash clear

Resources