What happens in a git merge?

Two branches, one history: how git finds the common ancestor and weaves the work together.

A branch is just a pointer to a chain of commits. When you merge, git finds the common ancestor of both branches, compares what changed on each side since then, and combines the changes.

If both sides touched different things, you get a merge commit with two parents and history stays intact. If both sides edited the same lines, git stops and asks you: that's a conflict, and it's a feature, not a failure.

Remember this

  • Merge starts from the common ancestor commit
  • A merge commit has two parents
  • Conflicts mean both branches edited the same lines

Got a different question? SeaThru generates a fresh video for any topic where systems talk or data structures move.

Ask your own question →

Keep learning