13 Stashing (git stash
)
There are times when you may want to stash (set aside) your current work rather than commit.
Examples:
- Realized that you were working on the wrong branch
- Realized that you and your collaborator are working on the same lines and resolving conflicts may be difficult
- Need to immediately switch to another branch and do not want to commit the change
- Partial commit
## * master
## On branch master
## Changes to be committed:
## new file: temp_script.sh
##
## Untracked files:
## .gitignore
13.1 Stash
## Saved working directory and index state WIP on master: 196a84c Adding loss.txt while in detached HEAD
## stash@{0}: WIP on master: 196a84c Adding loss.txt while in detached HEAD
13.2 Unstash
## On branch master
## Changes to be committed:
## new file: temp_script.sh
##
## Untracked files:
## .gitignore
##
## stash@{0}: WIP on master: 196a84c Adding loss.txt while in detached HEAD
13.3 Delete Stash
## Dropped refs/stash@{0} (8671050f90b16604533352792efdf7fe2163fa21)
Note: You can perform both git stash apply
and git stash drop
at the same time by entering git stash pop
.