Interview Prep/Git & GitHub/Merge, rebase and cherry-pick

How does a three-way merge work?

IntermediateConceptMerge, rebase and cherry-pick
Answer

Git finds the merge base (the best common ancestor), then compares each side against it. A hunk changed on only one side is taken automatically. A hunk changed on both sides differently is a conflict. This is why merging the same branch twice is safe: the new merge base is the previous merge commit.

git merge-base main feature
All Git & GitHub questions Roadmap: Git & GitHub

More on Merge, rebase and cherry-pick