Git Stash
git stash temporarily saves uncommitted changes (staged and unstaged) so you can switch branches or pull updates without committing half-done work.
Basic Example
# You have uncommitted changes but need to switch branches
git stash
# Switch branches, do other work...
git checkout main
git pull
# Come back and reapply your changes
git checkout feature-login
git stash pop
Key Commands
git stash # stash tracked changes (staged + unstaged)
git stash -u # also stash untracked files
git stash list # view all stashes
git stash show -p stash@{0} # view the diff of a specific stash
git stash pop # apply the latest stash and remove it from the list
git stash apply stash@{1} # apply a specific stash but keep it in the list
git stash drop stash@{0} # delete a specific stash without applying it
git stash clear # delete all stashes
Naming a Stash
git stash push -m "WIP: login validation logic"
Makes it easier to identify later in git stash list:
stash@{0}: On feature-login: WIP: login validation logic
pop vs apply
| Command | Applies changes | Removes from stash list |
|---|---|---|
git stash pop |
✅ | ✅ |
git stash apply |
✅ | ❌ (stays until manually dropped) |
tags in git
- In git we create a tag to represent some milestone.
- most of the organizations create a tag on every release
- Tag points to a specific commit and will not move.
- git tags Refer Here for docs
