What is Git Stash?

What is Git stash and how to use Stashing and Cleaning?

When you have been working on part of your project and things are in a messy state and you want to switch branches for some other work. The problem is that you don’t want to do a commit of half done work so you can get back to this point later. In such situations git stash command is very useful.

Stashing takes the your modified tracked files and staged changes and saves it on a stack of unfinished changes that you can reapply at any time even on a different branch.

Below are commands to work with stash on git:

git stash or git stash push  To save your changes in a stack.

git stash apply:  To apply recent saved stash.

git stash list: To list your stashed changes.

git stash show: To see what n is in the below commands.

git stash apply stash@{n}: To apply a specific stash from list.

git stash drop stash@{n}: To delete a specific stash from list. 


The changes to your files were reapplied, but the file you staged before wasn’t restaged. To do that, you must run the git stash apply command with a --index option to tell the command to try to reapply the staged changes.

If you want to know in detailed manner refer to the below URL: