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
git branch
touch temp_script.sh
git add temp_script.sh
git status
## * master
## On branch master
## Changes to be committed:
## new file: temp_script.sh
##
## Untracked files:
## .gitignore
13.1 Stash
git stash
git stash list
## 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
git stash apply
git stash list
## 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
git stash apply --index
git stash list