TortoiseGit Manual

Stash Changes

Often, when you’ve been working on part of your project, things are in a messy state and you want to switch branches for a bit to work on something else. The problem is, you don’t want to do a commit of half-done work just so you can get back to this point later. The answer to this issue is the git stash command.

Stashing takes the dirty state of your working directory — that is, your modified tracked files and staged changes — and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).

Tip

There is a similar function in TortoiseGit called changelists (the section called “Change Lists”) which can be used to structure commits.

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, right click on a folder to pop up the context menu and then select the command TortoiseGitStash changes A dialog will pop up where you can optionally enter a message for this state:

Figure 2.52. Stash changes dialog

Stash changes dialog


You can also select include untracked, to stash untracked files away, too. To stash all files away, including ignored files in addition to the untracked files, select --all.

When TortoiseGit detects that a stashed changes exist, the context menu will be extended:

Figure 2.53. (un)stash options

(un)stash options


The stash is implemented as a stack. Stash Apply will apply the changes of the latest stash to your working tree. Stash Pop does the same, but will remove the latest stash from the stack after applying it. Stash changes is still possible and will stash the current changes of the working copy to the top of the stack. Stash List provides an overview of all the whole stash stack. You can also remove and view the stashed changes there (similarly to the the section called “Log Dialog” and the section called “Reference Log”).

Conflicts

Although major merge work is done by git automatically applying a stash, a conflict may happen during cherry-picking (i.e., a file was modified in your current branch and also in the stash), please see the section called “Resolving Conflicts” on how to resolve conflicts.

Please note, that "REMOTE"/"theirs" in the conflict editor refers to the to be merged stash and "LOCAL"/"mine" to your version in the working tree before you applied the stash.

You can find more information at git-stash(1) man-page.