Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge and rebase branch into master without conflicts

Tags:

git

Here is our current feature branch work flow ->

  • From the master create a new feature branch.
  • Commit work to the feature branch.
  • Merge the master into the feature branch as we work to keep it up to date.
  • If there are conflicts resolve them. This creates a "Merge master into Feature_Branch" commit in the feature branch.
  • When the feature branch is complete, merge the feature branch back into master.

Problem:

If we do a merge --squash of the feature branch into the master, we have no issues. If we do a regular merge and then rebase we have to resolve all the conflicts again. On a feature branch with 100's of commits this is a major pain.

Is there a way to merge the feature branch back into master and rebase without conflicts?

like image 345
Kenoyer130 Avatar asked Oct 21 '25 16:10

Kenoyer130


1 Answers

I think you are fighting with this thing: Rebasing a Git merge commit

Try enabling rerere and using git rebase with -p option.

If I understood well, -p asks Git to try reusing previously-stored conflict resolutions upon stumbling on them during rebase, and rerere is a, say, "plugin", that enabled git to, literally, "REuses REcorded REsolutions".

Sometime ago there was an article here but it seems down now. Maybe you'll find that on internet-archive.

So, I've just looked up another one, it seems to explain things nicely:

Rerere Your Boat...

i.e.:

With rerere turned on you can merge occasionally, resolve the conflicts, then back out the merge. If you do this continuously, then the final merge should be easy because rerere can just do everything for you automatically.

This same tactic can be used if you want to keep a branch rebased so you don't have to deal with the same rebasing conflicts each time you do it. Or if you want to take a branch that you merged and fixed a bunch of conflicts and then decide to rebase it instead - you likely won't have to do all the same conflicts again.

See the highlight. Seems just what you are doing.

But, before you jump with "geez, why isn't that enabled by default?!" take some care and see also this : https://stackoverflow.com/a/5521483/717732 and along with rerere learn the rerere forget. Just in case!

like image 163
quetzalcoatl Avatar answered Oct 23 '25 07:10

quetzalcoatl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!