Git stash

The git stash command temporarily stores your modified files, allowing you to switch branches or work on something else without losing your changes. It is particularly useful when you need to quickly move to another task without committing your current changes.



Initial Example

$ git stash




Tutorials dojo strip

STASH Options

OptionDescription
-a, --allValid for push and save commands. Stashes all ignored and untracked files, then cleans them up with git clean.
-u, --include-untrackedValid for push and save commands. Stashes all untracked files, then cleans them up with git clean. For show command, shows untracked files in the stash entry as part of the diff.
--no-include-untrackedSkips untracked files during stashing for push and save commands.
--only-untrackedValid for the show command. Displays only the untracked files in the stash entry as part of the diff.
--indexValid for pop and apply commands. Tries to reinstate both working tree and index changes, but may fail with conflicts.
-k, --keep-indexValid for push and save commands. Keeps changes already added to the index intact.
--no-keep-indexOpposite of --keep-index, not keeping changes in the index.
-p, --patchValid for push and save commands. Interactively select hunks to be stashed, keeping the index state. Implies --keep-index.
-S, --stagedValid for push and save commands. Stashes only staged changes, similar to committing to stash instead of branch.
--pathspec-from-file=<file>Valid for push command. Reads pathspec from <file> instead of command line arguments. If <file> is -, reads from standard input.
--pathspec-file-nulValid for push command with --pathspec-from-file. Pathspec elements are separated by NUL and taken literally.
-q, --quietValid for apply, drop, pop, push, save, store commands. Suppresses feedback messages.
--Valid for push command. Separates pathspec from options for disambiguation.
<pathspec>Valid for push command. Stashes only the files matching the pathspec, leaving others intact.
<stash>Valid for apply, branch, drop, pop, show commands. Refers to a specific stash in the form stash@{<revision>}. Assumes latest stash if none is given.




Examples

1. Basic Stash

Temporarily stores your modified files.

$ git stash

2. View All Stashes

Displays a list of all stashes.

$ git stash list

3. Apply a Stash

Applies the most recent stash to your working directory.

$ git stash apply

4. Apply a Specific Stash

Applies a specific stash from the list.

$ git stash apply stash@{1}

Replace stash@{1} with the identifier of the stash you want to apply.

5. Drop a Stash

Removes a specific stash from the list.

$ git stash drop stash@{1}

Replace stash@{1} with the identifier of the stash you want to drop.

6. Clear All Stashes

Clears all stashes from the list.

$ git stash clear

Scroll to Top