Using Source Control with BitBucket, Source Tree and Visual Studio – Part 3

Conflicts are caused when two branches both have changes to the same file that could potentially overwrite each other. Source control keeps track of these kinds of changes and will alert the developer to these issues. Resolving conflicts is an important part of being able to use source control. Conflicts are discovered when trying to merge one branch into another. In the last part of this series we are going to look at how to manage conflicts with SourceTree.

Creating a Conflict

You can view what is conflicting in the window at the lower right hand corner of the SourceTree application. Compare the content of high-lighted and non-highlighted regions between the “<<<<<>>>>>” characters. The conflicting code listed first (below “<<<<<>>>>>” indicates the beginning of the conflicting code from the branch that was to be merge in. The name of this branch is listed after the “>>>>>>>” characters.

When conflicts arise use the following process to resolve the conflict.

  • Resolving on the master branch
    • Select the “Uncommitted changes” line in the commits grid
    • Switch back to Visual Studio and open the page(s) that contain the conflict which are indicated in SourceTree with an exclamation point icon.
    • When you switch to Visual Studio the program will tell you that changes have been made and ask if you would like to refresh the editor. Click “Yes” to confirm the refresh to view the conflicts.
    • The code for the conflicts is now populated on the page.
    • The code located under “<<<<<<< HEAD” is the code that is from the current branch.
    • Following the “=======” is the code that is from the branch the is trying to be merged in.
    • At this point make the necessary changes to the code to resolve the conflict by deleting the Git indicators and adding or removing any other code to fix the conflict and save the page.
  • Switch back to SourceTree and commit your changes.
  • Double click on the feature branch that you tried to merge into master before the conflict to make it the active branch.
  • Right click on the master branch and select “Merge master into current branch”. Click OK to merge.
  • At this point the conflict should be resolved and the branches merged.
  • If other conflicts were indicated repeat the steps to resolve all conflicts on each page displayed in SourceTree.

Resolving Conflicts (PDF)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s