Stashing
Git stashing allows you to temporarily save changes in your working directory (modified or
staged files) without committing them. This is useful when you need to switch branches or work on something else
but are not ready to commit your current work.
When you stash changes, Git stores them in a stack (a list of stashes), which you can apply later to continue
where you left off.
Use Cases:
- Experimenting without creating multiple commits
- Cleaning up before pulling changes from remote
- Avoiding unwanted commits in a branch
- Saving changes temporarily wile debugging
- Switching to a different task on short notice
Examples:
Creating a new stash (any untracked files will not be stashed):
git stash
Stash both tracked and untracked files
git stash -u
list all local stashes
git stash list
Apply most recent stash to working branch and remove from stash list
git stash pop
Apply most recent stash to working branch but keep it in the stash list
git stash apply # Applies the most recent stash
git stash apply stash@{index} # Applies a specific stash by index
Delete all stashes from the list
git stash clear
Delete a specific stash from the list
git stash drop # Drops the most recent stash
git stash drop stash@{index} # Drops a specific stash by index