Resolving Merge Conflicts
If two branches change the same part of a file in different ways, Git can pause the merge and ask you to choose the final content.
On this page
Make two branches edit the same line
Start from a clean main in project-notes after the branching lesson. Create a file with one line, then change that line differently in each branch. The final merge should report a conflict in status.txt.
printf 'Draft\n' > status.txt
git add status.txt
git commit -m "Add draft status"
git switch -c update-status
printf 'Ready for review\n' > status.txt
git commit -am "Mark status ready for review"
git switch main
printf 'Review scheduled\n' > status.txt
git commit -am "Schedule review"
git merge update-status
Choose the final content and complete the merge
Run git status to find conflicted files. Open status.txt and look for the lines starting with <<<<<<<, =======, and >>>>>>>. Replace the entire marked block with the agreed wording, save, stage the file, and commit. To cancel an in-progress merge instead, use git merge --abort before committing it.
git status
printf 'Ready for scheduled review\n' > status.txt
git add status.txt
git commit -m "Resolve project status conflict"
git status