Course Git & GitHub for Beginners

Conflicts

Branching & Merging Preview

Merge conflicts

When two branches edit the same lines differently, Git cannot decide for you. It marks the file and asks you to choose.

The conflict markers

<<<<<<< HEAD\nconsole.log("v1");\n=======\nconsole.log("v2");\n>>>>>>> feature

Resolving

  1. Open the conflicted file
  2. Choose one side, both, or a new version
  3. Delete the <<<<<<< markers
  4. git add file.txt
  5. git commit to finish the merge

Prevent conflicts

  • Pull/merge from main into your branch often
  • Keep changes small and focused
  • Communicate who owns which files
  • Merge branches quickly, don't let them age

In an editor

VS Code shows conflicting blocks with "Accept Current / Accept Incoming / Accept Both" buttons — point and click, then commit.

Conflicts are normal

Everyone hits them. A clean resolution is part of the job — not a failure.

Tip: The longer a branch lives, the bigger the conflicts. Merge early, merge often.

This is a free preview lesson

Enroll in the Git & GitHub for Beginners to unlock every lesson, lesson PDF guides, quizzes and your certificate - and start creating your own pieces today.


Discussion

Free preview lesson