Skip to content

Conflict Resolution

When two people edit the same sentence: Merge conflicts are like two people editing the same paragraph in a document simultaneously — Git can not automatically decide which version is correct, so it asks you to choose or combine them manually.

Why it matters: Conflicts are inevitable in team projects. Understanding how to resolve them quickly and correctly prevents lost work, corrupted merges, and frustrated developers.

The key insight: The best way to handle conflicts is to prevent them — small, frequent merges reduce the likelihood of conflicts, and good communication about who is working on what avoids overlapping changes.

A merge conflict occurs when Git’s three-way merge algorithm cannot automatically reconcile changes from two branches. This happens when both branches modify the same region of the same file in different ways.

flowchart TD
    A["Both branches modify<br/>different files"] --> B["Auto-merge: no conflict"]
    C["Both branches modify<br/>different regions of the same file"] --> B
    D["One branch modifies,<br/>other deletes the same file"] --> E["Conflict"]
    F["Both branches modify<br/>the same region of the same file"] --> E
    G["Both branches add<br/>a file with the same name<br/>(different content)"] --> E
    H["One branch renames,<br/>other modifies the original"] --> I["Possible auto-resolve<br/>(rename detection)"]

    style B fill:#e8f5e9
    style E fill:#ffcdd2
    style I fill:#fff3e0

When a conflict occurs, Git writes conflict markers into the file:

<<<<<<< HEAD
int authenticate(User *user) {
return verify_password(user->password, user->stored_hash);
}
=======
int authenticate(User *user) {
Token *token = jwt_sign(user, SECRET_KEY);
return token->value;
}
>>>>>>> feature-auth
MarkerMeaning
<<<<<<< HEADStart of conflict region. Our version begins.
=======Separator between our version and their version.
>>>>>>> feature-authEnd of conflict region. Their version ends.

The text after >>>>>>> identifies the branch being merged.

When both sides of a conflict have been merged from a common branch, Git may produce multi-base conflict markers (with the ort merge strategy):

<<<<<<< HEAD
our version
||||||| merged common ancestors
base version
=======
their version
>>>>>>> feature-auth

The middle section (between ||||||| and =======) shows the common ancestor’s version, which can be helpful for understanding what changed on both sides.

The most common approach — edit the file to produce the correct result:

// After manual resolution:
int authenticate(User *user) {
// Verify password first (from HEAD)
if (!verify_password(user->password, user->stored_hash))
return NULL;
// Generate JWT token (from feature-auth)
Token *token = jwt_sign(user, SECRET_KEY);
return token->value;
}

Then stage and commit:

Terminal window
$ git add src/auth.c
$ git commit # (or git merge --continue / git rebase --continue)
  • Merging: Integration strategy that can produce conflicts requiring resolution.
  • Rebasing: Alternative integration strategy that avoids merge commits but replays commits.
  • Branching: Branch creation and management fundamentals that lead to parallel development.