Git - git-stash Documentation
English ▾ English Français Português (Brasil) Русский Svenska українська мова 简体中文 Topics ▾ Setup and Config git config help bugreport Credential helpers Getting and Creating Projects init clone Basic Snapshotting add status diff commit notes restore reset rm mv Branching and Merging branch checkout switch merge mergetool log stash tag worktree Sharing and Updating Projects fetch pull push remote submodule Inspection and Comparison show log diff difftool range-diff shortlog describe Patching apply cherry-pick diff rebase revert Debugging bisect blame grep Email am apply imap-send format-patch send-email request-pull External Systems svn fast-import Server Admin daemon update-server-info Guides gitattributes Command-line interface conventions Everyday Git Frequently Asked Questions (FAQ) Glossary Hooks gitignore gitmodules Revisions Submodules Tutorial Workflows All guides...
Administration clean gc fsck reflog filter-branch instaweb archive bundle Plumbing Commands cat-file check-ignore checkout-index commit-tree count-objects diff-index for-each-ref hash-object ls-files ls-tree merge-base read-tree rev-list rev-parse show-ref symbolic-ref update-index update-ref verify-pack write-tree Latest version ▾ git-stash last updated in 2.56.0 2.56.0 2026-09-28 2.55.0 2026-06-29 2.54.0 2026-04-20 2.53.0 no changes 2.52.0 2025-11-17 2.51.1 → 2.51.2 no changes 2.51.0 2025-08-18 2.43.1 → 2.50.1 no changes 2.43.0 2023-11-20 2.42.1 → 2.42.4 no changes 2.42.0 2023-08-21 2.39.1 → 2.41.3 no changes 2.39.0 2022-12-12 2.38.1 → 2.38.5 no changes 2.38.0 2022-10-02 2.35.1 → 2.37.7 no changes 2.35.0 2022-01-24 2.32.1 → 2.34.8 no changes 2.32.0 2021-06-06 2.31.1 → 2.31.8 no changes 2.31.0 2021-03-15 2.26.1 → 2.30.9 no changes 2.26.0 2020-03-22 2.24.1 → 2.25.5 no changes 2.24.0 2019-11-04 2.23.1 → 2.23.4 no changes 2.23.0 2019-08-16 2.22.1 → 2.22.5 no changes 2.22.0 2019-06-07 2.17.1 → 2.21.4 no changes 2.17.0 2018-04-02 2.16.6 2019-12-06 2.15.4 no changes 2.14.6 2019-12-06 2.13.7 2018-05-22 2.12.5 2017-09-22 2.11.4 2017-09-22 2.8.6 → 2.10.5 no changes 2.7.6 2017-07-30 2.1.4 → 2.6.7 no changes 2.0.5 2014-12-17 NAME git-stash - Stash the changes in a dirty working directory away SYNOPSIS git stash list [ <log-options> ] git stash show [ -u | --include-untracked | --only-untracked ] [ <diff-options> ] [ <stash> ] git stash drop [ -q | --quiet ] [ <stash> ] git stash pop [ --index ] [ -q | --quiet ] [ <stash> ] git stash apply [ --index ] [ -q | --quiet ] [ --label-ours= <label> ] [ --label-theirs= <label> ] [ --label-base= <label> ] [ <stash> ] git stash branch <branchname> [ <stash> ] git stash [ push ] [ -p | --patch ] [ -S | --staged ] [ -k | -- [ no- ] keep-index ] [ -q | --quiet ] [ -u | --include-untracked ] [ -a | --all ] [( -m | --message ) <message> ] [ --pathspec-from-file= <file> [ --pathspec-file-nul ]] [ -- ] [ <pathspec> …] git stash save [ -p | --patch ] [ -S | --staged ] [ -k | -- [ no- ] keep-index ] [ -q | --quiet ] [ -u | --include-untracked ] [ -a | --all ] [ <message> ] git stash clear git stash create [ <message> ] git stash store [( -m | --message ) <message> ] [ -q | --quiet ] <commit> git stash export ( --print | --to-ref <ref> ) [ <stash> …] git stash import <commit> DESCRIPTION Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.
The command saves your local modifications away and reverts the working directory to match the HEAD commit. The modifications stashed away by this command can be listed with git stash list , inspected with git stash show , and restored (potentially on top of a different commit) with git stash apply . Calling git stash without any arguments is equivalent to git stash push . A stash is by default listed as "WIP on <branchname> …", but you can give a more descriptive message on the command line when you create one.
The latest stash you created is stored in refs/stash ; older stashes are found in the reflog of this reference and can be named using the usual reflog syntax (e.g. stash@{0} is the most recently created stash, stash@{1} is the one before it, stash@{2.hours.ago} is also possible). Stashes may also be referenced by specifying just the stash index (e.g. the integer <n> is equivalent to stash@{ <n> } ). COMMANDS push [ -p | --patch ] [ -S | --staged ] [ -k | -- [ no- ] keep-index ] [ -u | --include-untracked ] [ -a | --all ] [ -q | --quiet ] [( -m | --message ) <message> ] [ --pathspec-from-file= <file> [ --pathspec-file-nul ]] [ -- ] [ <pathspec> ...] Save your local modifications to a new stash entry and roll them back to HEAD (in the working tree and in the index).
The <message> part is optional and gives the description along with the stashed state. For quickly making a snapshot, you can omit "push". In this mode, pathspec elements are only allowed after a double hyphen -- to prevent a misspelled subcommand from making an unwanted stash entry. save [ -p | --patch ] [ -S | --staged ] [ -k | -- [ no- ] keep-index ] [ -u | --include-untracked ] [ -a | --all ] [ -q | --quiet ] [ <message> ] This option is deprecated in favour of git stash push .
It differs from "stash push" in that it cannot take pathspec. Instead, all non-option arguments are concatenated to form the stash message. list [ <log-options> ] List the stash entries that you currently have. Each stash entry is listed with its name (e.g. stash@{0} is the latest entry, stash@{1} is the one before, etc.), the name of the branch that was current when the entry was made, and a short description of the commit the entry was based on. stash@{0}: WIP on submit: 6ebd0e2...
Update git-stash documentation stash@{1}: On master: 9cc0589... Add git-stash The command takes options applicable to the git log command to control what is shown and how. See git-log[1] . show [ -u | --include-untracked | --only-untracked ] [ <diff-options> ] [ <stash> ] Show the changes recorded in the stash entry as a diff between the stashed contents and the commit back when the stash entry was first created. By default, the command shows the diffstat, but it will accept any format known to git diff (e.g., git stash show -p stash@{1} to view the second most recent entry in patch form).
If no <diff-option> is provided, the default behavior will be given by the stash.showStat , and stash.showPatch config variables. You can also use stash.showIncludeUntracked to set whether --include-untracked is enabled by default. pop [ --index ] [ -q | --quiet ] [ <stash> ] Remove a single stashed state from the stash list and apply it on top of the current working tree state, i.e., do the inverse operation of git stash push .
The working directory must match the index. Applying the state can fail with conflicts; in this case, it is not removed from the stash list. You need to resolve the conflicts by hand and call git stash drop manually afterwards. apply [ --index ] [ -q | --quiet ] [ <stash> ] Like pop , but do not remove the state from the stash list. Unlike pop , <stash> may be any commit that looks like a commit created by stash push or stash create . branch <branchname> [ <stash> ] Creates and checks out a new branch named <branchname> starting from the commit at which the <stash> was originally created, applies the changes recorded in <stash> to the new working tree and index.
If that succeeds, and <stash> is a reference of the form stash@{ <revision> } , it then drops the <stash> . This is useful if the branch on which you ran git stash push has changed enough that git stash apply fails due to conflicts. Since the stash entry is applied on top of the commit that was HEAD at the time git stash was run, it restores the originally stashed state with no conflicts. clear Remove all the stash entries.
Note that those entries will then be subject to pruning, and may be impossible to recover (see EXAMPLES below for a possible strategy). d
The rest of this page is on the live site.