~/
hackweb.dev
Stashing Changes
Quiz
⌘K
...
~/
/tutorials
/git/git-stash/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
Comment
0 / 300
Typo
Grammar
Broken link
Clarify
Code
en/tutorials/git/13git-stash
Write
Preview
Diff
# Stashing Changes Stashing lets you temporarily shelve changes so you can work on something else, then come back to them later. It's like putting your work in a drawer. ## Creating a Stash ```bash git stash ``` This saves your staged and unstaged changes and reverts your working directory to the last commit. You can add a descriptive message: ```bash git stash save "WIP: login form styling" ``` Without a message, Git generates a default one based on the branch and commit. ## Managing Stashes ```bash git stash list # See all stashed changes git stash pop # Apply most recent stash and remove it git stash apply # Apply without removing from list git stash drop # Delete most recent stash git stash clear # Remove all stashes ``` Stashes are stored in a stack. `pop` and `apply` work on the most recent one by default. ## Viewing Stash Contents ```bash git stash show # Quick summary of changed files git stash show -p # Full diff of changes in the stash git stash show stash@{2} # Show a specific stash ``` This helps you identify which stash contains the changes you need. ## Stashing Specific Files ```bash git stash push -m "only package.json changes" -- package.json ``` This stashes only the specified files, leaving everything else intact. ## When to Use Stash - Switching branches with uncommitted work - Pulling changes when you have local modifications - Quick context switches during debugging - Experimenting without creating a commit - Cleaning your working directory temporarily ## Best Practices - Use descriptive messages: `git stash save "add user avatar upload"` - Don't stash too many times — commit or discard instead - Pop stashes promptly to avoid losing track of them - Test after applying a stash to ensure nothing broke - Keep your stash list small by using it as a temporary holding area ## Common Mistakes - Forgetting that `stash pop` can cause merge conflicts - Leaving stashes unattended for too long - Using `git stash` without checking `git stash list` first - Assuming stash is a substitute for committing - Not using `-m` and ending up with hard-to-identify stashes
No changes yet
Reset to original
Submit suggestion
cancel