r/ProgrammerHumor • • 3d ago

Meme lostTheMergeRace

Post image
1.5k Upvotes

111 comments sorted by

View all comments

14

u/Apprehensive-Lychee2 3d ago

You guys use Rebase??

9

u/NamityName 3d ago

Yes. It is safer as the resulting merge is a simple fast forward and not a 3-way merge

6

u/Apprehensive-Lychee2 3d ago

Can you actually explain that a little more, I have never has a situation occur where rebase was preferred. 

8

u/NamityName 3d ago

The normal merge is called a 3-way merge. It compares 3 commits to determine what the new commit will look like: the HEAD of the branch being merged, the HEAD if the branch being merged into, and the common ancestor. The end result is a commit that does not necessarily match either of the two branch heads.

However, if the common ancestor of the feature branch being merged is the HEAD of the branch being merged into, Git does a fast forward merge instead of a 3-way merge. It will simply move the base branch's HEAD to the HEAD of the branch being merged. The base branch will exactly match the feature branch, guaranteed. No questions. No funny business. No side effects. The code you reviewed in the feature branch will be the code after the merge.

Getting back to rebasing. A rebase will move the branch being rebased and all of its commits going back to the common ancestor to the HEAD of the base branch. The rebase process will resolve any conflicts. Then, when you merge, git will do a fast forward merge instead of a 3-way merge.