1

I have been using Git for a while and I know basics of merging, tho I have one confusion on how others maintain the code changes after merging?

I have master branch, and feature_a branch which is created from master. There are some changes in master branch and as well as feature_a branch, to get latest changes in master I merged feature_a into master branch.

So now master has all the latest changes, and now i want to continue in feature_a branch to add more changes, but the thing is feature_a does not have changes of master branch which are made after branch out and before merge, which is bothering me from continuing on feature_a branch.

Am I missing any concept or is there any way to keep both branches on same level after merging? Should I merge master in to feature_a after merging feature_a into master ?

LeGEC
  • 46,477
  • 5
  • 57
  • 104
Darshan
  • 515
  • 1
  • 3
  • 16

1 Answers1

1

but the thing is feature_a does not have changes of master branch which are made after branch out and before merge, which is bothering me from continuing on feature_a branch.

Then all you need to do is rebase the new part of feature_a on top of master:

git switch feature_a
git rebase --onto master A feature_a

You would go from

m--m--M--m (master)
     /
 a--A--a--a (feature_a)

To

m--m--M--m  (master)
     /    \
 a--a      --a'--a' (feature_a)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Ok so after each merge (feature_a into master) I need to rebase feature_a on master, after that i can continue on feature_a for next change and do the same thing when i again need to merge it, is that correct ? – Darshan Mar 12 '21 at 10:07
  • 1
    @Darshan That is the general idea, yes. I do the rebase only of the part from `feature_a` which is not yet merged into `master`. – VonC Mar 12 '21 at 10:14
  • What do you mean by "rebase only of the part from 'feature_a' which is not yet merged" ? Do i need to skip the merge part? – Darshan Mar 12 '21 at 11:46
  • 1
    @Darshan That is what the `rebase --onto` does in my answer: rebase everything after `A`: `A` is the last commit from `feature_A` being merged to `master`. – VonC Mar 12 '21 at 11:59