DEV Community

Cover image for Temporary saving of work using git stash
Đặng Đình Sáng
Đặng Đình Sáng

Posted on

Temporary saving of work using git stash

Introduction

git stash to temporarily save changes you are working on.

How to use it

Save changes temporarily

git stash
Enter fullscreen mode Exit fullscreen mode

This saves the changes in your current working directory to a stash, leaving your working directory clean.

Apply the stash

git stash apply
Enter fullscreen mode Exit fullscreen mode

This applies the latest stash to the current working directory. The stash remains in place and can be reapplied.

Apply and remove the stash

git stash pop
Enter fullscreen mode Exit fullscreen mode

This will apply the latest stash and remove it from the stash at the same time.

Display a list of stashes

git stash list
Enter fullscreen mode Exit fullscreen mode

This will display a list of saved stashes.

Apply a specific stash

git stash apply stash@{1}
Enter fullscreen mode Exit fullscreen mode

If multiple stashes exist, you can apply a specific stash by using the format stash@{n}.

Drop a specific stash

git stash drop stash@{1}
Enter fullscreen mode Exit fullscreen mode

To drop a specific stash, use the following command.
This will remove the stash at stash@{1}.

Conclusion

A git stash is useful for temporarily storing changes you are working on so you can do other work or switch branches.

Top comments (0)