Resolve A Conflict
Part of the Version Control section of Coddy's Terminal journey — lesson 38 of 58.
Aborting is sometimes the right move, but most of the time you want to actually resolve the conflict and finish the merge.
Resolving a conflict is a three-step ritual:
- Open the conflicted file. Replace the marker block with the version you want (or a combination).
- Stage the resolved file with
git add. - Finalize the merge with
git commit.
You can use a script to overwrite the file with the resolved content directly, which is exactly what you will do in this lesson (no editor needed).
If you forget to git add the resolved file, the commit will fail and tell you the file is still marked as unmerged.
Challenge
MediumSet up a conflict on notes.txt exactly like the previous lesson:
- Initial commit on
mainwith contenthello - On branch
alt: change tohi from alt, commit - Back on
main: change tohi from main, commit - Run
git merge alt(it will conflict)
Resolve the conflict by overwriting notes.txt with the line hi from both. Stage the file and finalize the merge with the message Resolve notes. Print the final contents of notes.txt.
Cheat sheet
To resolve a merge conflict:
- Edit the conflicted file — remove conflict markers and keep the desired content.
- Stage the resolved file:
git add <file> - Finalize the merge:
git commit
git add notes.txt
git commit -m "Resolve conflict"If you skip git add, the commit will fail with the file still marked as unmerged.
Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Version Control
2Getting Started
Initialize A RepositoryThe .git FolderConfigure Your IdentityGit StatusRecap - First Repo8Merging
What Is A MergeFast-Forward MergeThree-Way MergeMerge ConflictsResolve A ConflictRecap - Merge Master11Feature Branch Project
Project OverviewInitialize Main3Tracking Changes
The Staging AreaGit AddGit CommitModifying A Tracked FileGit LogRecap - First Commits6Recipe Site Project
Project OverviewInitialize And Ignore