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:
- 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.
- 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.
- 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?