How to stash changes in Git
Today, we’ll show you how to use git stash to save changes temporarily. You may need to save your work momentarily at times. So you may accomplish it with the git stash command.
- How to change commit message that already pushed in Git
- How to push code to GitHub using git bash
- How to set Git username and email address
- Git Installation on Windows – A Step-by-Step Guide
- Check list of stashed changes
- Save changes
- Save changes including untracked files
- Save changes with description
- Re-apply saved changes
- Re-apply saved changes and remove it from stash list
1. Check list of stashed changes
You can check stashed changes anytime by running the following command in the terminal.
git stash list
2. Save changes
To save changes temporarily, you have to run the following command.
git stash
Above command will stash only modified files. It’ll not include untracked files.
3. Save changes including untracked files
To save changes including untracked files, run stash command along with --include-untracked
. Check the following command.
git stash --include-untracked
OR
git stash -u
4. Save changes with description
It’s good practice to save changes with a small description. So that changes could be easy to identify. Use the command git stash save "message"
to stashes with description.
git stash save "your message will come here..."
5. Re-apply saved changes
To re-apply stashed changes, run the following command.
git stash apply
6. Re-apply saved changes and remove it from stash list
If you want to re-apply the stashed changes and also want to remove it from the stash list then you can use pop
.
git stash pop
That’s it for today.
Thank you for reading. Happy Coding..!!