Git flow question, one feature branch depends on another

219 views Asked by At

Git flow question, one feature branch depends on another. How should i correctly rebase the child feature branch after my parent feature branch merging to master?

The git flow is shown below: At last I got duplicate commits in my child feature branch.

enter image description here

2

There are 2 answers

0
j4ckofalltrades On

Assuming you've already committed your changes on your feature branch, you can just do:

git pull origin master --rebase

From git-pull Documentation:

More precisely, git pull runs git fetch with the given parameters and calls git merge to merge the retrieved branch heads into the current branch. With --rebase, it runs git rebase instead of git merge.

0
giacomolm On

Never tried, but rebase --onto ...[1] seems to be useful:

First let’s assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.

o---o---o---o---o  master
     \
      o---o---o---o---o  next
                       \
                        o---o---o  topic

We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master branch. We want our tree to look like this:

o---o---o---o---o  master
    |            \
    |             o'--o'--o'  topic
     \
      o---o---o---o---o  next 

We can get this using the following command:

git rebase --onto master next topic

[1] https://git-scm.com/docs/git-rebase#_description