Git stash commands
Git stash provides a convenient way to temporarily store and manage unfinished changes in your codebase, allowing you to switch context, work on different tasks, or collaborate with others without committing incomplete code.
In this section, we will explore a range of Git stash commands that enable you to stash changes, apply and manage stashed changes, and clear or list stashes. By mastering these commands, you can effectively manage your work-in-progress changes, switch between branches, and maintain a clean and organized codebase.
Git stash commands offer flexibility and convenience, empowering you to keep your codebase free from unfinished or experimental changes while you focus on other tasks. Stashing allows you to save your progress without cluttering your commit history and provides a seamless way to switch between branches or work on urgent bug fixes.
Explore these Git stash commands and unlock the power to handle unfinished changes with ease.
Stash current changes
$ git stash save
The stash command saves your local modifications and reverts the working directory to match the HEAD
commit.
You may choose to omit save. If you do specify save, you can enter a message to label the stash content (e.g., git stash save “making a big change”).
Show stash list
$ git stash list
Recover changes from stash
$ git stash pop
The latest stash will be restored on your current work.
Adding a parameter of the stash ID (eg. stash@{1}
) will restore this specific stash to your current work.
Delete stash
$ git stash drop
The latest stash will be deleted.
Adding a parameter to the stash ID (eg. stash@{1}
) will delete this specific stash.
Delete all stashes
$ git stash clear