Git & GitHub Course
Git & GitHub
/
Intermediate

Merge Conflicts

Definition

An event that occurs when Git is unable to automatically resolve differences in code between two commits. This usually happens when two branches modified the exact same line of the exact same file.

Explain Like I'm New

Developer A changes the title to 'Hello World'. Developer B changes the title to 'Welcome to App'. They both try to merge their code into `main`. Git throws its hands up and says: 'I am a robot, I don't know which one is correct! You are a human, you fix it!'

Real World Example

A terrifying red error message in your terminal stating `CONFLICT (content): Merge conflict in index.html`. Your code is paused, and Git injects weird `<<<<<<<` symbols into your file.

Common Use Cases

  • •Team collaboration realities

Terminal Output

bash / terminal
/* What a file looks like during a Merge Conflict: <<<<<<< HEAD (Current branch: main) <h1>Hello World</h1> ======= <h1>Welcome to App</h1> >>>>>>> feature-login (Incoming branch) To fix it, you literally just delete the symbols (<<<, ===, >>>) and type out what you want the final code to look like. */

Interview Questions

basic

  • Does a merge conflict destroy your code?

intermediate

  • How does Git physically mark a conflict inside the file?

Flash Cards

Question

Destroy code?

Click to reveal answer
Answer

No! It just pauses the merge process safely. Your code is fine, Git is just waiting for you to tell it what to do.

Question

How marked?

Click to reveal answer
Answer

It injects conflict markers: `<<<<<<< HEAD` (your current code), `=======` (the divider), and `>>>>>>> branch-name` (the incoming code).