Search code examples
gitmergeversion-controlgit-merge

Keeping changes same in merging branches in


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 ?


Solution

  • 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)