9. Stash

Sometimes you’re working on a new feature or bugfix, but then you need to switch to a new topic while your files are not complete yet. You don’t want to commit your changes (yet), and thus you leave the files in place.

Usually you can leave the files in a modified state and not commit them, but there are situations where this might not be possible or preferable:

  • You’ve to edit the same file for the new feature and now you’ve a conflict

  • You don’t want to accidentally commit the changes

  • You need to switch branches which would result in a conflict

In this case you’ve 2 options:

  • You commit those changes to a new branch

  • You don’t want to commit those changes, but “cache” them locally

This is where the Git stash comes in play.