Reputation: 31481
In using Git, I try to make one small change at a time and commit each change separately. This lets me have detailed commit messages, and lets me revert individual changes easily, as described in this blog post (not mine). Sometimes when working on one large feature, I will see a small unrelated bug that I would like to fix. As per my current system, I have to note the bug to fix later (usually as a code comment), commit the large feature, then go back and fix the bug.
I am wondering if branches will let me make fix the bug and push the commit immediately, while I finish the feature in another branch. Can I push the fix to both the public repository and to my 'adding feature' branch? Branches seem a bit unwieldy for this, is there a simpler method to get the result I'm looking for?
Upvotes: 2
Views: 965
Reputation: 93720
You ask if branching is a solution to your problem, so I won't assume you are already on a branch like other answers.
It's very easy to address your problem in a single branch. It's why git
distinguishes the working copy from changes staged to be committed. In your case, fix the bug and use git add -p
to add only the patchset you care about. You can use git add <file>
if you don't have any other work in the same file. Then git commit
(note, not git commit -a
, which implies adding everything) that one patch and resume your feature work.
I frequently use this for the reason you describe, and then for the final feature checkin I used it again to split the major feature into smaller atomic checkins (if applicable).
Upvotes: 1
Reputation: 44377
It sounds like you should be developing your feature in a feature branch (see, for instance, this branching model).
So you do your feature work in your feature branch. When a bug fix is needed, you
Upvotes: 2