Managing Merge Conflicts | Bondar Academy
Course: Git and GitHub Fundamentals
Module: Working with Git and GitHub
Instructor: Artem Bondar
Lesson Summary
Merge conflicts are a common challenge when working with Git . They occur when Git cannot determine the correct version of code from different branches. This lesson demonstrates how to resolve merge conflicts using Visual Studio Code . Understanding Merge Conflicts A merge conflict arises when multiple contributors make changes to the same line of code in different branches. In this example: Artem creates a branch called Artem's change and modifies a line of code. A second user creates a branch called third line and makes a conflicting change to the same line. Resolving Merge Conflicts When attempting to merge the second user's branch into the master branch, Git identifies a conflict: Artem's pull request merges successfully. The second user's pull request fails with a message indicating a conflict. Steps to Resolve the Conflict: Run the command: git merge origin master Open the merge editor in Visual Studio Code to view the conflict. Choose one of the following options to resolve the conflict: Accept current changes (keep changes from the working branch). Accept incoming changes (keep changes from the master branch). Manual edit to combine changes from both contributors. Complete the merge and synchronize changes. After resolving the conflict, the remote repository will reflect the new commit, and the master branch will be updated without any conflicts. Visual Studio Code's merge conflict editor simplifies this process, allowing users to easily choose the desired code version.