AcademyTimeline Architect: Mastering the Time MachineProtocol 4: Crisis Management

Lesson 1: The Negotiator (Merge Conflicts)

What happens when two people edit the same line of the same file? Git can't decide which version to keep. It raises its hands and says: "You figure it out." This is a merge conflict.

When Do Conflicts Happen?

Conflicts occur when:

  • Two branches modify the same line of the same file.
  • One branch deletes a file that the other modified.
  • Both branches add a file with the same name.

What a Conflict Looks Like

When Git encounters a conflict, it marks the file with special conflict markers:

<<<<<<< HEAD
const port = 3000;
=======
const port = 8080;
>>>>>>> feature/new-port
  • <<<<<<< HEADYour current branch's version.
  • ======= — The divider between the two versions.
  • >>>>>>> feature/new-port — The incoming branch's version.

How to Resolve a Conflict

Step 1: Identify the conflicting files

git status
# You'll see: "both modified: app.config"

Step 2: Open the file and decide

Edit the file to keep the version you want. Remove the conflict markers:

// BEFORE (with conflict markers):
<<<<<<< HEAD
const port = 3000;
=======
const port = 8080;
>>>>>>> feature/new-port

// AFTER (your decision):
const port = 8080;

Step 3: Mark as resolved

git add app.config

Step 4: Complete the merge

git commit -m "Resolve port conflict, use 8080"

Tips for Resolving Conflicts

  • 🧠 Understand both sides before choosing.
  • 📞 Talk to the other developer if you're unsure.
  • Run tests after resolving to make sure nothing broke.
  • 🔍 Use git diff to double-check your resolution.
booting...

Mission Objective

Experience your first merge conflict:

  1. Set the stage: Create a branch with git checkout -b conflict-demo.
  2. See the conflict: Run cat app.config to view the conflict markers.
  3. Resolve it: After editing, mark the file as resolved with git add app.config.

Real-World Wisdom

Senior engineers say: "The best way to handle merge conflicts is to prevent them." Keep branches short-lived, merge frequently, and communicate with your team about which files you're editing.

Mission Control

Create a conflicting situation

Expected Command

git checkout -b conflict-demo

View the conflict markers

Mark the conflict as resolved