ProgramGuru

Resolve merge conflicts without guessing

Resolve merge conflicts without guessing

A conflict happens when Git cannot safely choose one combined result. It is a request for a human decision, not proof that the repository is broken.

What you’ll learn

  • Read conflict markers.
  • Resolve and stage a conflict.
  • Abort a merge when appropriate.

Conflict resolution is a decision workflow

  1. Detect

    Git identifies paths it cannot combine safely.

    unmerged paths
  2. Decide

    Create the intended final content.

    human resolution
  3. Record

    Stage and complete the merge.

    resolved merge
resolved merge

Resolve meaning, not just markers

During a conflicted merge, Git writes conflict markers such as <<<<<<<, ======= and >>>>>>> into affected text files. Your job is to produce the final intended file, remove the markers and test it.

After resolving a path, stage it with git add. When all conflicts are resolved, complete the merge with git commit or the merge continuation appropriate to your Git version/workflow. git merge --abort attempts to return to the pre-merge state.

Finish a conflicted merge deliberately

Run this in a disposable practice repository unless the lesson explicitly says otherwise.

git status
# edit conflicted files and remove markers
git add path/to/resolved-file
git status
git commit

# Or, before resolving:
# git merge --abort

git status lists unmerged paths. Staging a resolved file tells Git that you have chosen its final content; it does not merely mean 'include this file.'

Practice: Resolve merge conflicts

Your task: Create two branches that edit the same line differently. Merge them, inspect both versions, write a third final line that reflects the intended behavior, stage it and complete the merge.

Common pitfall to avoid

Do not resolve conflicts by blindly choosing 'ours' or 'theirs' everywhere. Either side may contain required work, and the correct result can be a combination of both.

Check your understanding

What does git add mean for a conflicted file after you edit it?
Choose one answer. You can try again.

Answer and explanation

It marks your current file content as the resolved version for the merge.

Correct.

Resolve merge conflicts: what to remember

Resolve merge conflicts without guessing is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.

Read further: official supporting documentation.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Undo safely with restore, reset and revert →