I'm basing my Git repo on A successful Git branching model and was wondering what happens if you have this situation:

enter image description here

Say I'm developing on two feature branches A and B, and B requires code from A. The X node introduces an error in feature A which affects branch B, but this is not detected at node Y where feature A and B were merged and testing was conducted before branching out again and working on the next iteration.

As a result, the bug is found at node Z by the people working on feature B. At this stage it's decided that a bugfix is needed. This fix should be applied to both features, since the people working on feature A also need the bug fixed, since its part of their feature.

Should a bugfix branch be created from the latest feature A node (the one branching from node Y) and then merged with feature A? After which both features are merged into develop again and tested before branching out?

The problem with this is that it requires both branches to merge to fix the issue. Since feature B doesn't touch code in feature A, is there a way to change the history at node Y by implementing the fix and still allowing the feature B branch to remain unmerged yet have the fixed code from feature A?

Mildly related: Git bug branching convention

  • 6
    Can't you just fix the bug in the 'develop' branch and then merge it into both feature A and feature B?
    – tdammers
    Commented Jun 24, 2012 at 10:42
  • Hmm, seems like that would be best. There might be merge conflicts in feature A but I think that's inevitable here. Commented Jun 24, 2012 at 10:46
  • If you haven't done any further development on the 'development' branch, and the bugfix does not overlap any changes in the 'feature A' branch, then you won't get any conflicts.
    – tdammers
    Commented Jun 24, 2012 at 10:48

3 Answers 3


Use a distinct commit to fix the bug in one branch, then cherry-pick that commit into the other branch.

  • That works well, cheers. Commented Jun 24, 2012 at 14:06

Arguably, there is no bug in A or X. Fix the bug in branch B where it was found. The fix will propagate to X and A in the normal course of events.

  • Thanks, that's also feasible as long as the bug doesn't affect feature A. Commented Jun 25, 2012 at 13:38

Although not a popular workflow in git, a workflow which is popular in Mercurial would be to update to revision X, fix the bug there (as X2) and then redo merge Y (which would have been a pair of merges in Mercurial).

In fact, this workflow is easier in git since after everyone has switched from Y to Y2 then the refs to the original Y will be lost and it will eventually be garbage collected. In hg you would have had to manually strip those commits to tidy up your repository.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.