Git Stash Commands
git stash temporarily saves uncommitted changes so you can switch branches or work on something else without committing incomplete code.
| Command | Description |
|---|---|
git stash | Saves changes to tracked files and cleans those changes from the working directory. |
git stash push -m "Working on login authentication" | Saves changes with a descriptive message. |
git stash -u | Saves changes to tracked files and untracked files. |
git stash list | Lists saved stashes, such as stash@{0} and stash@{1}. |
git stash show -p | Shows the full diff in the latest stash. |
git stash pop | Applies the latest stash and removes it from the list if successful. |
git stash apply | Applies the latest stash and keeps it in the list. |
git stash pop 'stash@{2}' | Applies a specific stash and removes it from the list if successful. |
git stash drop 'stash@{1}' | Permanently deletes the specified stash. |
git stash clear | Permanently deletes all stashes. Use with caution. |
Stashes are stored in the repository and can be applied on the same branch or another branch. If you set skip-worktree on a file, clear that flag before stashing changes to that file.