Video in progress

Junior 🌿 Git

What is a merge conflict and when does it happen?

When two branches have changed the same place in the same file in different ways, Git cannot decide which version is right and leaves the decision to you. That is a conflict.

📖 Answer

If different files, or different parts of one file, were changed, Git merges them itself. The problem comes up only when the same lines were edited on both sides. Another case: one branch deleted a file and the other modified it.

In a conflicted file Git puts markers:

<<<<<<< HEAD
int timeout = 30;
=======
int timeout = 60;
>>>>>>> feature/retry

You keep the right version (or combine both), delete the markers, then run git add and git commit (in a merge) or git rebase --continue (in a rebase).

The way to reduce conflicts is not to keep branches around for long and to update from main often.