How does git help deal with the scenario below:
I have a task broken down into 2 parts: backend task and frontend task. I make a pull request to merge the backend changes and wait for it to be merged (and address feedback). While waiting, I can't really work on the frontend changes because it depends on backend changes and those are not available on the master branch yet.
What is the best way to pull in changes to frontend changes branch from the backend changes branch while it is still being reviewed?
Best Answer
Hold on, skip merging
For this approach, you do not want to merge your
feature_a
intofeature_b
repeatedly.Rebasing has been mentioned in other answers, but only for rebasing things onto
master
. What you want to do in your case is:Start your
feature_b
fromfeature_a
, i.e.:Whenever
feature_a
changes while it is waiting to get merged intomaster
, you rebasefeature_b
on it:Finally, as soon as
feature_a
has been merged intomaster
, you simply get the newmaster
and rebasefeature_a
onto it a last time:This final rebase will graft all commits that are dangling from the
feature_a
commit (which is now irrelevant as it has been merged intomaster
) right ontomaster
. Yourfeature_b
is now a simple, standard branch going right frommaster
.EDIT: inspired from the comments, a little heads up: if you need to make some change which affects both features, then be sure to make it in
feature_a
(and then rebase as shown). Do not make it in two different commits in both branches, even if may be tempting; asfeature_a
is part of the history offeature_b
, having the single change in two different commits will be semantically wrong and possibly lead to conflicts or "resurrections" of unwanted code, later.