The more I use Git, the more I like it. Fact.
You know when you are in the middle of something, it is not done yet, and someone call you with a bug for you to fix it? What do you do with your unfinished business?
Git has a command called stash. Stash is a separated area from your commits, which purpose is exactly that, to save unfinished work. And its use is very simple.
git stash save
This command saves the changes in the current working directory and clears the log to your last commit.
For instance, let’s say you have a project with a version 1 already done and you are in the middle of version 2, and of course, you have created a branch for that.
Then, while you are in the middle of another feature, there’s a bug to fix in version 1. Your git status at this moment would look like this:
You can’t commit yet, because if you do that, the build will break, and your are to much of a responsible guy to do that, aren’t you? So what to do?
Here’s when git stash comes to play. With the command: git stash save – you’ll have the following result:
The buffer gets cleared, and you now can checkout version 1.0, fix the bug, commit it, get back to version 2.0 and rebase it.
When you reach that point just executes command: git stash pop – to get your unfinished changes back.
Done, your back in the game, exactly were you left it.
There are a lot more options within stash command. I recommend you take a look at git’s documentation.