Stashing (and applying) your code
There are a few scenarios where it makes sense to make a temporary, local copy of your changes. Sometimes you are in the middle of working on a feature and the following happens:
- Another priority comes up, requiring you to shift gears and quickly fix a bug.
- You have to review a pull request (covered near the end of this chapter) and need to check out a different branch.
- The code is working, but not quite the way you want it to and you want to do potentially risky refactoring.
In these scenarios, the stash function (git stash
) can be a good option to use. This allows you to save the state of the code you are working on for now and look at the original branch, or switch to another branch, without any pending changes.
In the following screenshot, from Visual Studio 2019 for Windows, an optional message is entered to describe the stash and then either Stash All or Stash All and Keep Staged is clicked instead of Commit Staged:
...