Last Updated on January 30, 2021 by sandeeppote

git-stash is used to record the current state of the working directory and the index and want to clean the directory with the intent of applying or dropping the stashed changes to the working directory. Suppose there are changes made to a file in working directory but before committing those changes you are willing to pull the changes from master. Stash the changes made to working directory-

git-branch-9

Stash Changes

 git stash

You may also stash changes with comments-

git stash save "Content updated to stash"

git-branch-10

You can stash multiple times, while stashed git reference this with unique name i.e. stash@{0}, stash@{1} and so forth. You may also switch between the branches once stashed as the recorded copy is available between the branches.

If you want to see the stash list

 git stash list

git-branch-11

Revert Stashed Changes
To apply stashed changes made to the working directory, use either-

 git stash pop

This shall apply/merge changes to the working directory and remove it from stash list.

 git stash apply

This shall apply/merge changes to the working directory but still keep the copy of stash.

Removing stashed changes
To delete specific stash item use-

 git stash drop stash@{0}

To delete all stash items-

 git stash clear

Use Stash clear wisely as it is destructive.