...

/

Stash Working Directory

Stash Working Directory

Learn to temporarily save noncommitted changes so we can switch between branches without losing our work.

In Git, we have different undo approaches for different scenarios. It depends on what we need to do.The following is a list of scenarios in which an undo action is required:

  • Amend the last commit.

  • Reset several commits.

  • Revert changes after pushing to a remote branch.

  • Rebase commits into another commit.

Sometimes, we may start changing our code before switching to a new branch. For example, assume that we’re working in the master or development branch with a clean working directory. Now, we change something in the code file, and then we realize we need to create a new feature branch for that change.

The git stash command

We can use git stash to temporarily save our current changes.

 ...