tags: #git
---
### Stashing your work
- `git stash` - stash tracked files
- `git stash -p` - partial stash (goes through each changed "hunk" in your working copy and ask whether you wish to stash it)
- `git stash -u` - stash including untracked files (ex: new files that are not staged)
- `git stash -a` - stash including ignored files (ex: .env files)
- `git stash push -u -m "message"` - stash including untracked files with message
### Re-applying stashed changes
- `git stash pop` - removes the changes from your stash and reapplies them to your working copy
- `git stash apply` - reapply the changes to your working copy and keep them in your stash
- This is useful if you want to apply the same stashed changes to multiple branches
### Managing multiple stashes
- `git stash list` - list of all stashes
- `git stash save "message"` - save stash with a name to identify at later time easily
- ex: `git stash save "add style to our site"`
- `git stash pop stash@{2}` - choose a stash index from pop list and apply
### Viewing stash diffs
- `git stash show` - summary of a stash
- `git stash show -p` - to view the full diff of a stash
### Creating a branch from stash
- `git stash branch add-stylesheet stash@{1}` - This checks out a new branch based on the commit that you created your stash from, and then pops your stashed changes onto it.
### Cleaning up stash
- `git stash drop stash@{1}` - drop stash with id stash@{1}
- `git stash clear` - delete all your stashes
---
sources: https://www.atlassian.com/git/tutorials/saving-changes/git-stash