When two branches modify the same lines in the same file, Git cannot merge automatically and asks you to decide. Conflict resolution is scary the first time, much less scary the second.
How a conflict happens
Imagine: on main, line 1 of README.md says "Hello". On your branch my-feature, you changed it to "Hi". Meanwhile, someone on main changed it to "Hey". Git does not know which one to keep.
When you run the merge:
Git stops with a message: CONFLICT (content): Merge conflict in README.md.
Reading the conflict markers
Open the conflicted file. You see something like this:
<<<<<<< HEAD
Hey
=======
Hi
>>>>>>> my-feature<<<<<<< HEAD: start of the conflict block, version from the current branch (heremain).=======: separator between the two versions.>>>>>>> my-feature: end of the block, version from the incoming branch.
Resolve the conflict
Edit the file manually to keep what you want. Delete all three markers and write the final version:
Hello and heyOr keep one of the two versions, or write something completely different. You decide.
Finalize the resolution
Once all conflicted files are edited, stage them and commit:
Git auto-generates a merge commit message, which you can accept or edit.
To see which files are still in conflict at any point:
Conflicted files appear under "both modified". As long as any remain, the merge is not complete.
Abort a merge in progress
If you realize you took the wrong approach and want to cancel everything:
Git restores the exact state from before the merge. Nothing is lost.
git-scm.com - git merge