Git stash

I use Git when working on my WordPress projects.

On occasion, when I’m working on the latest branch and testing out some changes, styling, code etc, I’m *really* excited that I’ve squashed that bug / made that visual improvement.
However, it’s only then that I realize I didn’t create a new branch for my current round of changes.

So, it’s copy/paste, multiple CTRL-Z’s and then paste in. But wait! The changes are in multiple files. Darn.

Have no fear. Git can help.

At the command line:

git stash
git stash branch new-fix-feature-branch-name-you-should-have-created-in-the-first-place

Git stashes the original changes, then creates and checks out the new branch name I provide and places me in the new branch *and* applies the changes.

The changes that were stashed and then applied to the new branch are also removed from the “stash pile” by design and upon successful application.

And Voila! Sanity replaces profanity.