What is best practice for updating feature branches to a new base?

1.1k views Asked by At

I use git flow and I have a question about best practice when branching making feature branches. If I have a develop main branch and two feature branches, one branched at time t2 and the other branched at t3, what should be done if both feature branches are not ready to merge and need something new from the develop branch or from the other feature branch? Is there a way to update the "base" of feature 1 from develop at t2 to a new "base" of develop at t3 when something new has been done with develop? And similarly for feature branch 2, when it is not ready for merging, can it be updated with new changes from the develop branch before we merge it?

                         feature 1 (branch)
                        /
                       /  
    ----- develop ----/-----\---------------------------
                             \
                              \
                              feature 2 (branch)
    t1              t2     t3                      t4

Can the branches somehow be "moved forward" so that new changes in develop branch get included with the feature branches or is it necessary that we merge first?

3

There are 3 answers

1
morxa On BEST ANSWER

I want to complement the two existing answers: instead of merging develop in the feature branches, you could also instead rebase each feature branch on the updated develop branch:

git checkout feature
git rebase develop

Advantages:

  1. The history becomes somewhat clearer, because you avoid merge commits such as Merge branch develop into feature, which may be confusing when you're later merging feature into develop.
  2. Additionally, you can easily change commits in your feature branch (e.g. if you want to fix a typo in a commit message) without changing the commits already in the develop branch. If you merge develop into feature, this is no longer possible, because the branches will then diverge and you can no longer merge feature into develop.

So this approach is slightly more work (rebase instead of merge), but also brings some (minor) advantages.

0
David Deutsch On

While you could move them forward with a rebase, I would just merge develop into the feature branches. When working on a feature branch, I regularly merge develop into it anyway, to prevent huge merge conflicts when I eventually merge the feature branch back into develop.

0
Math On

You can merge the point of the develop branch you want in feature.

If you only want some specific commits, you can use git cherry-pick to apply the changes of those commits to your branch.