Loading lesson path
A merge conflict happens when two branches change the same part of a file. Git can't decide which change to keep, so you have to choose. You must resolve the conflict before you can finish the merge.
Merge conflicts usually happen when you merge branches that changed the same lines in a file.
Formula
This is common in collaborative projects or when working on long - lived branches.When you merge a branch and there are conflicting changes, Git will pause and mark the files with conflicts.
If there are conflicts, Git will tell you which files are affected.
Use git status to see which files need your attention:
Use git diff to see what changed and help you decide how to resolve the conflict:
Open the conflicted file. You'll see sections like this:
<<<<<<< HEAD
=======
Formula
>>>>>>> feature - branchEdit the file to keep what you want, then remove the conflict markers ( <<<<<<<, =======, >>>>>>> ).
After fixing the file, mark it as resolved:
Example: Mark Resolved git add filename.txt
Finish the merge with a commit (if Git doesn't do it automatically):
If you want to stop and undo the merge:
Example: Abort Merge git merge --abort
If you prefer, you can use a visual tool to resolve conflicts:
If you want to keep only your changes or only the other branch's changes:
Example: Keep Our Changes git checkout --ours filename.txt
Example: Keep Their Changes git checkout --theirs filename.txt Troubleshooting & Best Practices If you're stuck, you can always use git merge --abort to start over. Make sure you remove all conflict markers before marking as resolved. If you use git mergetool and don't like the result, you can still edit the files by hand.