Managing Merge Conflicts

Merge Conflicts

Practice a Merge Conflict

If you would like to try to fix a merge conflict using the GitHub Extension for Visual Studio, use the following steps:

  1. Click Create under GitHub on the Team Explorer Pane.
  2. Name the new GitHub repository Conflicts, and include a quick description.
  3. Click Create.
  4. While on the master branch, create a New branch… named Change1. Uncheck the Checkout branch option then click the Create Branch button.
  5. Repeat the last step, but name the other branch Change2, making sure that it’s based on the master branch.

    Even though we haven’t made changes to any of the branches, use master as the branch your new branches are based on to ensure you don’t encounter any issues.

  6. Checkout the Change1 branch and add the following content on line 2 and line 3:
    • Line 2: I am making a change on line 2.
    • Line 3: I am making a change on line 3.
  7. Stage and Commit the changes you made on the Change1 branch.
  8. Checkout the Change2 branch and add the following content on line 2 and line 3:
    • Line 2: I am making a change on line II.
    • Line 3: I am making a change on line III.
  9. Stage and Commit the changes you made on the Change2 branch.
  10. Checkout the master branch.
  11. On the Home screen of the Team Explorer pane, select Branches.
  12. Select Merge.
  13. In the Merge from branch drop-down, select Change1.
  14. Click the Merge button.
  15. On the Home screen of the Team Explorer pane, select Branches.
  16. Select Merge.
  17. In the Merge from branch drop-down, select Change2.
  18. Click the Merge button.
  19. A merge conflict has occurred, click the Conflicts: 1 option from the Team Explorer - Branches pane.
  20. Select the README.md file and click Merge.

    Explore the new Merge window that is displayed. Two panes are displayed, Source and Target. The Source pane is based on the Change2 branch and the Target pane is based on the master branch.

  21. Click the Take Right button.
  22. Save the change by clicking the Save button or pressing CTRL+S on your keyboard.
  23. Click Accept Merge. The README.md file now displays the changes you selected.
Tell me why
Continue