2

I've got a question regarding git branching protocol. I'm starting to get more familiar with the git commands, but am still fairly new to the process.

I'm working on a git-based project with one other person. We're adding a large feature, so we isolated our working into 'Branch_1'. The other developer started working on a bunch of additions in a fork of Branch_1 called Branch_2. The other dev did some work on Branch_2 and then went on to other tasks temporarily. I needed to continue and extend the changes that he made in Branch_2, so I created Branch_3 based on Branch_2.

Figure 1

Branch_1
  |_______> Branch_2  (other developer working on)
                |________> Branch_3  (I'm working on)

While I'm working on Branch_3, I realize a bug FIX that needs to be part of all the branches, and I need the FIX in order to continue with developing Branch_3. (Also, if Branch_3 work is abandoned, the FIX need to be in all the other branches regardless).

So my thought is to checkout Branch_1, make the changes for the FIX, checkout Branch_2, merge in Branch_1, then checkout Branch_3 and merge in the changes from Branch_2. See figure 2 below.

Figure 2

git checkout Branch_1
# make my changes
git pull origin Branch_1  # to pull in any other changes
git push origin Branch_1 

git checkout Branch_2
git pull origin Branch_2    # to pull in any other changes
git merge --no-ff Branch_1  # merge in branch 1 
git push origin Branch_2    # push to the remote repository  

git checkout Branch_3
git pull origin Branch_3    # to pull in any other changes
git merge --no-ff Branch_2  # merge in branch 2
git push origin Brach_3     # push to the remote repository 

However, I wonder about several things in this case:

  1. There are a lot of steps to do. Gets time consuming after awhile. If I create a Branch_4 based off of Branch_3 and a Branch_5 off of Branch_4, yet more steps are involved.
  2. In order to proceed with Branch_3 work after making the FIX, I basically have to make commits to my co-worker's Branch_2 which he might not realize.
  3. For more complicated setups, I might not relize what branched from what. I could make my bug FIX to Branch_1 and merge it into my co-workers Branch_2, but perhaps my co-worker had created Branch_2 by branching off of some intermediary branch such as Branch_1a. The FIX would not have been properly merged into Branch_1a in the right order.

I'm mainly wondeirng how others would approach a similar situation. Is this the right mindset when making a change that needs to be in a hierarchy of branches?

Robin Green
  • 32,079
  • 16
  • 104
  • 187
Joe J
  • 9,985
  • 16
  • 68
  • 100
  • 1
    See also http://stackoverflow.com/questions/6596030/whats-your-ideal-branch-architecture-within-git-for-web-applications and its answers – The Nail Jan 27 '12 at 08:27

1 Answers1

2

Unfortunately, yes. If you want to integrate a fix into all branches you have to either make it once and merge it everywhere or make the fix multiple times (supported by cherry-pick). When worrying about branch2 and that you’re making commits that your coworker is unaware of, just omit branch2. When your coworker eventually merges it back into branch1 (which should be the desired outcome because the secret to successful working with branches is actually merging back again) the fix will automatically incorporated. If he desperately needs the fix you could simply notify him and he can merge it himself.

Bombe
  • 81,643
  • 20
  • 123
  • 127
  • Thank you Bombe. That's good to know that I don't have to merge Branch_1 into Branch_2, and can just merge it into my own Branch_3. – Joe J Jan 27 '12 at 18:32
  • Note that if you are used to merging from branch2 into branch1, you *will* get merge conflicts if commits from branch3 have already been merged directly into branch1 before! – The Nail Jan 29 '12 at 13:33