Quick git tip - stash and stash pop
I'll be moving these quick tips into their own section of the site when I get the time/can be bothered, but until then they'll be showing up here.
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:
- git stash
- git checkout dev
- git checkout -b css-fix
- 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.