Hands-On: A Real Merge Conflict

Updated

October 30, 2026

Hands-On: Simulate a Real Merge Conflict

Two branches edit src/ping.py on Linux. You merge, resolve markers, and delete the feature branch.

Setup

Start from a clean ~/desk/desk-api (chapter 3 hands-on).

cd ~/desk/desk-api
git switch main
git status

Branch A — JSON ping

git switch -c feat/ping-json
cat > src/ping.py <<'EOF'
def ping():
    return {"status": "ok"}
EOF
git add src/ping.py
git commit -m "feat(ping): return a dict"
git switch main

Branch B — string change on main

cat > src/ping.py <<'EOF'
def ping():
    return "OK"
EOF
git add src/ping.py
git commit -m "feat(ping): shout the status"

main and feat/ping-json have diverged.

 A ← B ← C ← shout     main          ping.py returns "OK"
           ↖
             dict      feat/ping-json  ping.py returns {"status": "ok"}

Merge and conflict

git merge feat/ping-json
git status
cat src/ping.py

You should see markers. Open the file in nvim (or your editor) and make it:

def ping():
    return {"status": "OK"}

No marker lines left.

git add src/ping.py
git commit -m "merge feat/ping-json"
git log --oneline --graph --decorate -8
git branch -d feat/ping-json

Done when

  • git status is clean on main
  • src/ping.py returns a dict with "OK"
  • feat/ping-json is deleted
  • git log --graph shows a merge commit (two parents)

If you want to retry: git reset --hard to the commit before the merge (only on this lab clone), or copy the repo and run the page again. Chapter 9 rebases this same divergence into a straight line instead.