git stash
Temporarily stores modified tracked files and staged changes on a stack so you can switch branches.
Syntax
git stash [push] [<options>] [--] [<pathspec>...]
Options
- push: Saves local modifications to a new stash entry (default subcommand)
- -m <message>: Adds a description to the stash entry
- -u / --include-untracked: Also stashes untracked files
- -a / --all: Stashes all files including ignored files
- -p / --patch: Interactively select hunks to stash
- pop: Applies the top stash and removes it from the stash list
- apply [<stash>]: Applies a stash without removing it from the list
- list: Lists all stash entries
- drop [<stash>]: Removes a single stash entry
- clear: Removes all stash entries
- show [<stash>]: Shows the changes recorded in the stash
Example
git stash
git stash push -m "work in progress"
git stash list
git stash pop
git stash apply stash@{1}Tip
Use git stash push -m with a descriptive message so you remember what each stash contains.