Git stash¶
Git stash is a command-line utility used to temporarily save (shelve) uncommitted changes in a Git working directory, allowing the user to switch contexts or work on other branches without losing incomplete work^[600-developer-tools-git-git-command.md].
Core Commands¶
The stash operation supports several sub-commands to manage the stack of saved changes^[600-developer-tools-git-git-command.md]:
git stash: Saves the current modifications to a new stash entry and reverts the working directory to match theHEADcommit (clean state).git stash list: Displays a history of all currently stashed entries.git stash apply: Re-applies the most recently stashed changes to the working directory but keeps the entry in the stash list.git stash pop: Re-applies the most recent changes (likeapply) and immediately removes that entry from the stash list.git stash clear: Permanently deletes all entries from the stash list.
Usage Scenarios¶
Stashing is useful when you need to quickly change branches or perform a pull operation but are not ready to commit your current work^[600-developer-tools-git-git-command.md].
Recovering a Clean State¶
If the working directory has become messy or corrupted, git stash can be used to quickly move modifications out of the way^[600-developer-tools-git-git-command.md]. Subsequently, git reset --hard can be used to reset the directory to a clean state relative to the last commit^[600-developer-tools-git-git-command.md].
Related Concepts¶
- [[Git]]
- [[Version Control]]
- Git Reset
Sources¶
600-developer-tools-git-git-command.md