Skip to content

Git stash workflow for temporary changes

Git stash is a workflow utility for temporarily storing changes that are not ready to be committed. It allows developers to save their current work state (modified tracked files and staged changes) and revert the working directory to match the HEAD commit, often to switch branches or perform a pull operation cleanly^[600-developer__tools__git__git-command.md]. This process can be reversed to restore the saved changes to the working directory^[600-developer__tools__git__git-command.md].

Core Commands

The stash workflow relies on a set of commands to manage the stack of temporary states^[600-developer__tools__git__git-command.md].

  • Save changes: git stash takes all modified files and stages them into a temporary stash on a stack.
  • Restore changes: git stash apply reapplies the most recently created stash to the working directory, but keeps the stash in the list for potential reuse.
  • Restore and remove: git stash pop reapplies the most recent stash and simultaneously removes it from the stash list^[600-developer__tools__git__git-command.md].
  • List history: git stash list displays all currently saved stashes, allowing the user to review the stack of temporary changes^[600-developer__tools__git__git-command.md].
  • Clean up: git stash clear permanently deletes all entries from the stash history^[600-developer__tools__git__git-command.md].

Common Use Cases

Stashing is particularly useful when a developer needs to pause their work context.

  • Branch Switching: If a developer has uncommitted work on the current feature branch but needs to urgently fix a bug on master, they can use git stash to hide their work, checkout master, and apply the fix.
  • Synchronizing: When pulling new updates from a remote repository, local changes may cause conflicts. Stashing local modifications allows for a clean pull, after which the stashed changes can be restored and merged with the incoming updates.
  • [[Git workflow]]
  • [[Commit]]

Sources