Merging changes and resolving conflicts

Sometimes, team members work on the same files at the same time, leading to conflicts. Let's see how to merge changes and resolve conflicts in such a scenario:

  1. Create a text file called HelloWorld.txt and add it to your local repository. Push the file to the server, and update the file both on the server and in your local repository.
  2. If you try to push a HelloWorld.txt file that has been modified both locally and in the remote repository, you get an error message, and the push fails:
  1. When looking in the output window, you get additional information on the possible reason why your push failed, as follows: Error: Hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same reference. You may want to first integrate the remote changes (for example, git pull) before pushing again.
  1. Click on the Pull link and you will get the remote changes, which will result in a conflict between your local copy and the remote one. Click on either the Resolve the conflicts or the Conflicts link:
  1. You will now see a list of conflicting files. Click on the conflict you want to resolve, and then click on the Merge button:
  1. You will see the conflicting modifications. Choose which ones you want to keep (the left one, the right one, or both), and click on the Accept Merge button:

  1. Back in the Team Explorer - Resolve Conflicts window, click on the Commit Merge button:

  1. Enter a comment, and click on the Commit All button to finalize and commit the merge locally:

  1. After the commit has been created locally, click on the Sync link, and then on the Push link:

  1. You should now see that the changes have been uploaded to the remote repository:

In this section, we have seen the basic usage of Git, using mainly the Visual Studio development environment, but it must also be noted that you can also use the command line to effect the same commands. There are other software applicationssuch as GitHub Desktop, Git Extensions, and many morethat are designed to help you interact with your repositories, as an abstraction, but they all use the same git commands as underlying instructions to the VCS, and they all use similar terminology for most commands.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.19.26