Git stash command

By using the git stash, git provides a way for stashing the uncommitted changes, before switching to another branch, so that we can return to them later, without having to make unnecessary commits.

Running git stash will take all uncommitted changes (staged and unstaged) and stash them, reverting the changes in our working copy.

Bash

git stash

git stash pop
Use git stash pop to remove the most recently stashed changes in our stash and re-apply them to our working copy.

Bash

git stash pop
Your image is not available

Viewing Stashes
To view all the stashes run the following git command.

Bash

git stash list

Note:
Here stash@{0} is the most recent stash.

git stash apply
We can use git stash apply to apply whatever is stashed away, without removing it from the stash. This can be useful if we want to apply stashed changes to multiple branches.

Bash

git stash apply

Applying Specific Stashes
When we run git stash apply, git assumes we want to apply the most recent stash, but we can also specify a particular stash by specifying the stash-id, like git stash apply stash@{2}

Syntax
git stash apply <stash id>

Bash

git stash apply stash@{2}

Dropping Stashes
To delete a particular stash from the stash queue, we can use the command.

Syntax
git stash drop

The above command is used to remove the most recent stash.

By using the stash-id, we can delete the specified stash from the queue.

Syntax
git stash drop <stash-id>

Bash

git stash drop stash@{2}

Clearing all Stashes
To delete all the stashes from the stash queue, run the following command.

Bash

git stash clear