SourceTree
Git
Conflict Resolution
Interactive
Visual Tools

How to interactively visually resolve conflicts in SourceTree / git

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Sure! Here's a detailed article on how to interactively (visually) resolve conflicts using SourceTree, integrated with Git:


When working collaboratively with Git repositories, encountering merge conflicts is inevitable. SourceTree, a popular Git graphical user interface (GUI), simplifies conflict resolution by providing a visual, interactive way to manage changes. This article delves into the technical aspects of using SourceTree to efficiently resolve merge conflicts with hands-on guidance and examples.

Understanding Merge Conflicts

Before jumping into SourceTree, it's crucial to understand what merge conflicts are. These occur when changes from different branches clash and Git cannot automatically integrate them. This typically happens when multiple collaborators modify the same lines within a file. SourceTree's visualization tools allow users to quickly identify conflicts, examine the changes, and decide how to best merge them.

Setting Up SourceTree for Conflict Resolution

  1. Install SourceTree: If SourceTree isn't already installed, download it from the official SourceTree website.
  2. Configure External Merge Tool: For optimal conflict resolution, configure an external merge tool within SourceTree like Beyond Compare, Araxis Merge, or even Visual Studio Code. This can be set up in SourceTree under `Tools > Options > Diff`.

When you encounter a conflict during a Git operation such as a merge or rebase, SourceTree flags these files and provides tools to handle them. Here’s a step-by-step guide:

Step 1: Start the Merge Process

  • Initiate a Merge: Pull the latest changes from the target branch. If there are conflicts, SourceTree will show a red exclamation mark next to the files.

Step 2: Open the Conflict Resolution Tool

  • Double-Click the File: In the `File Status` tab, you’ll find conflicted files. Double-click on any file to open the conflict resolver.
  • Review Changes: SourceTree will display a split view showing changes from both branches. The left pane shows `Their Changes`, the right pane displays `Your Changes`, and the middle pane (sometimes called the "result pane") is where you’ll combine these changes.

Step 3: Resolve Conflicts

  • Choose Changes: Decide between keeping your changes, their changes, or manually editing to amalgamate both sets of changes. This can be interactive with buttons or manually by editing the middle pane.
    • Click "Use Your Changes" to resolve the conflict by retaining your changes.
    • Click "Use Their Changes" to accept the changes from the incoming branch.
    • Edit Manually for a custom merge of changes.
  • Manual Adjustments: Directly edit the middle pane to combine changes uniquely. Use keyboard shortcuts for efficient navigation—typical shortcuts are `Ctrl + S` (or `Cmd + S` on Mac) to save changes and `Ctrl + W` to close the editor.

Step 4: Mark as Resolved

  • After resolving a conflict, mark it as resolved by clicking on the 'mark resolved' button within the conflict editor or through the toolbar within SourceTree.

Step 5: Commit the Merge

  • Once all conflicts are resolved, commit the merge to finalize and apply the changes. This is done through the `Commit` option where SourceTree enables tracking of resolved conflicts.

Additional Subtopics

Best Practices for Conflict Avoidance

  1. Frequent Pulling and Pushing: Regularly pulling updates from the upstream branch and pushing your changes reduces the window for conflict scenarios.
  2. Feature Branch Workflow: Maintain changes in feature branches, periodically syncing them with the main branch to minimize conflicts upon integration.
  3. Code Reviews and Communication: Establish clear communication and team-wide code review practices to catch potential conflicts early.

SourceTree Conflict Resolution Table

Here's a summary table for resolving conflicts using SourceTree:

ActionDescriptionSourceTree Feature
Start a MergeBegin merging changes from another branch or repository.Branch merging, fast-forward
Detect ConflictsIdentify files with conflicting changes.Conflict warnings, exclamation marks
Open Conflict EditorUse the visual tool to manage and resolve conflicts interactively.Embedded conflict editor, diff view
Choose ChangesDecide and apply your resolution strategy: theirs, yours, or custom.Use ‘Their Changes’, ‘Your Changes’
Manual EditsEdit directly in the merge result pane for custom resolutions.Result pane edits
Mark as ResolvedConfirm resolution and remove conflict markers.'Mark resolved' button
Commit the MergeFinalize the changes in your repository.Commit changes

By leveraging SourceTree's powerful features for validating and resolving merge conflicts, developers can maintain smooth collaboration within their projects. The visual interface not only makes conflict resolution more intuitive but also enhances productivity by focusing on decision-making rather than manual command-line interventions.

Incorporating these practices and tools will streamline your Git workflows, reducing the complexity associated with merge conflicts and ensuring a more stable and efficient development environment.


Course illustration
Course illustration

All Rights Reserved.