Merging, and What a Conflict Really Is
Merging. You switch back to the branch that should receive the work, then merge the other one into it.
`
git switch main
git merge add-contact-page
`
When main has not moved since you branched, git simply moves its pointer forward. That is a fast-forward, and it is the common case.
✦ A conflict is a question, not a failure
A conflict happens when the same lines changed on both branches, so git cannot know which version is right. It is not an error and nothing is broken. Git is asking you a question it genuinely cannot answer, because deciding which change is correct requires understanding what the code means. You open the file, choose, remove the markers, then add and commit.
What a conflict looks like.
`
<<<<<<< HEAD
<h1>Amara Okafor</h1>
=======
<h1>Amara Okafor, Developer</h1>
>>>>>>> add-title
`
Above the equals signs is what is on your current branch. Below is what is coming in. You delete the markers and leave the version you want, which may be a combination of both.
How to avoid most conflicts. Merge often and keep branches short lived. A branch open for a day conflicts rarely. A branch open for three weeks, while five other people edit the same files, conflicts constantly. The fix is a workflow habit rather than a git command.
Mark this lesson complete
Signed in, your progress follows you to every device.