CHAPTER 05
Resolving Merge Conflicts Manually
Updated: May 15, 2026
25 min read
# CHAPTER 5
Resolving Merge Conflicts Manually
1. Introduction
Analysis is complete; it is time for action. Resolving a merge conflict manually requires no special tools, no expensive IDEs, and no complex Git commands. It requires only a basic text editor, an understanding of the code's business logic, and meticulous attention to detail. In this chapter, we will walk through the exact keystrokes required to delete Git's conflict markers, synthesize conflicting code, and formulate the final commit that successfully ends the "Merging" state and restores harmony to the repository.2. Learning Objectives
By the end of this chapter, you will be able to:- Manually edit a file to remove Git conflict markers.
- Choose between keeping Current changes, Incoming changes, or a synthesis of both.
-
Use
git addto mark a conflict as resolved.
- Conclude the merge process with a final commit.
-
Abort a merge entirely using
git merge --abort.
3. Beginner Explanation
Imagine you are an editor finalizing a movie script.- The script has a conflict block. Writer A wrote: "The hero escapes in a car." Writer B wrote: "The hero escapes in a helicopter."
- The Fix: You open a word processor. You are the boss. You delete the ugly Git markers around the text. You delete the line about the car. You keep the line about the helicopter.
- You save the document.
-
You tell the publisher, "The script is fixed and ready to print" (This is
git add).
-
You officially publish it (This is
git commit).
4. The 4 Steps to Manual Resolution
Whengit status shows a file in red as both modified, you must follow this strict 4-step sequence to fix it.
-
1.
Open & Edit: Open the file in a raw text editor. Manually delete the
<<<<<<<,=======, and>>>>>>>lines. Keep only the code you want.
- 2. Save: Save the file to your hard drive.
- 3. Stage: Tell Git you have fixed the file by adding it to the staging area.
bash
bash
git merge --abort
``
This command instantly cancels the entire merge process, deletes all conflict markers, and restores your files exactly to how they looked 5 minutes ago before you ever typed git merge. It is the ultimate "undo" button.
8. Best Practices
-
Test Before Committing: Just because you deleted the conflict markers does not mean the code actually works! If you merged two complex PHP functions together, you might have accidentally created a syntax error. Always run your application locally (or run your unit tests) to verify the code executes flawlessly *before* you type the final git commit
.
9. Common Mistakes
-
Forgetting to Add: Beginners will painstakingly edit the file, save it, and immediately type git commit
. Git will throw an error saying "Umerged paths". You *must* rungit add <file>first. Usinggit addis how you officially communicate to Git: "I have reviewed this file and the conflict is formally resolved."
10. Exercises
- 1. What are the three logical choices a developer must choose between when resolving the code inside a conflict block?
- 2. What specific command transitions a file from a "conflicted" state to a "resolved" state in Git's eyes?