I've been using Git as source code management tool. For now my workflow is simple:
- think about a minimal new feature/refactoring
- code it
- review the diff with HEAD
- commit
I would like to improve this workflow, by making it more flexible. The reason is that I've encountered the following situation a couple of times, which I think is a typical one:
After a commit, I'm starting to modify the working directory in order to add a new feature.
I code for a while, let the state of the working directory be A at this moment. The important thing here is that is state A the working directory is not ready to be committed, because the new feature is not completed yet.
At this point I realize that it would be better to perform a refactoring first. Admit it, sometimes the need of a refactoring becomes obvious in the process of code modification.
Now I need to start again from HEAD and do the refactoring first. But I don't want to lose the modification of code HEAD -> state A. So basically I need to:
- do the refactoring in a copy of the working directory that is not altered yet after the last commit
- commit it
- merge the work on the new feature that I've started and stopped it when the working directory was in state A
- complete the work on the new feature
- commit it
I believe this is where branching can help me, but I'm having issues figuring the correct git commands. I'm confused by the fact that I need to create a branch when the working directory is altered after a commit and I don't know the correct way do deal with this.
What's the correct way to describe the above workflow in terms of Git commands?