Quick git tip - stash and stash pop

Here’s the scenario: you work on a branch called something like offline, commit the work, then spot an issue that can be fixed with CSS. Acting like you’re a magpie who’s seen something shiny you forget you’re on the offline branch and save a bunch of work.

Now when you go to commit you’re in a branch that doesn’t make sense for the work you’re doing, and if you try to checkout a different branch you can’t.

Here’s what to do:

  1. git stash
  2. git checkout dev
  3. git checkout -b css-fix
  4. git stash pop
And you’re in a more appropriate branch with your CSS changes unstaged.

What the stash command does is get rid of your changes since the last commit and keep them safe until you ask for them back again with stash pop. Simple and very useful.

git –help stash has much more information if you want a closer look.