AlgoMaster Logo

resolving conflicts

Last Updated: January 3, 2026

6 min read

Resolving conflicts in Git can feel daunting, but with the right understanding and techniques, you can navigate them with ease. When two branches have changes that overlap, Git is unable to automatically merge them, leading to conflicts that require your attention.

This chapter will demystify the process of resolving these conflicts, providing you with practical strategies and insights to handle them effectively.

Understanding Conflict Markers

When you encounter a merge conflict, Git marks the conflicting areas in your files using conflict markers. These markers help you identify which sections of code are in dispute.

The conflict markers look like this:

  • <<<<<<< HEAD: This marks the beginning of your changes.
  • =======: This separates your changes from the incoming changes.
  • >>>>>>> branch-name: This indicates the end of the incoming changes from the branch you're trying to merge.

When resolving conflicts, your first step is to carefully review these markers. You need to decide which changes to keep, whether to combine them, or to create a new solution entirely.

Strategies for Resolution

Conflicts can be resolved in several ways, depending on the nature of the changes and the desired outcome. Here are three common strategies:

Manual Resolution

This is the most straightforward approach. You manually edit the file, choosing which changes to keep.

  1. Open the conflicted file in your favorite text editor.
  2. Review the changes marked by Git.
  3. Edit the file to resolve the conflict. Ensure to remove the conflict markers.
  4. Once resolved, save the file.

After saving, you need to stage the resolved file:

Finally, commit the changes:

Using a Merge Tool

Many developers prefer using a merge tool for visual assistance in resolving conflicts.

Set up your preferred merge tool. For example, you can configure kdiff3:

When a conflict arises, invoke the merge tool:

The merge tool will show you the conflicting changes side by side, allowing for an easier visual resolution.

Once you finish resolving the conflicts in the tool, remember to stage and commit your changes.

Accepting Incoming Changes

In some cases, you may decide that the incoming changes are the most appropriate. You can choose to accept them outright using:

After this command, stage and commit the file as described earlier. This approach can be useful if the incoming changes are deemed more relevant or correct.

Common Conflict Scenarios

Understanding the scenarios where conflicts arise can help you prepare better. Here are some frequent situations:

Concurrent Edits

When two developers modify the same line in a file, a conflict occurs. For example, if Alice and Bob both change a line in app.js, their changes will conflict during a merge.

During the merge, Git will indicate a conflict, requiring resolution.

File Deletions and Modifications

If one branch deletes a file while another modifies it, a conflict will arise. This can happen when a developer decides a feature is unnecessary and removes the file, but another developer has already made changes to it.

When this happens, you’ll need to determine if the file should be restored, kept, or modified based on the context provided by both branches.

Merge Conflicts Across Multiple Files

Sometimes, a merge conflict may involve several files. Git will mark each conflicted file, allowing you to resolve them individually. Use the git status command to see all files in conflict:

This command will list files that require your attention, making it easier to tackle them systematically.

Automating with Git Commands

If you frequently find yourself dealing with merge conflicts, you can automate some common resolutions.

Using git rerere

Git has a feature called rerere (reuse recorded resolution), which can help automate conflict resolution. To enable it, run:

With rerere enabled, Git remembers how you resolved conflicts and applies the same resolution when similar conflicts occur in the future. This can save you time and reduce frustration.

Regularly Pulling Changes

Another preventive measure against conflicts is regularly pulling changes from the remote repository. This practice keeps your local branch up to date and minimizes the chances of conflicts when you eventually merge.

Regular communication with your team about ongoing changes also helps align efforts and reduces overlap.

Recovery Options and Best Practices

Sometimes, things don’t go as planned during conflict resolution. Understanding recovery options can save you headaches.

Undoing a Merge

If you realize that the merge is too complicated or the conflicts are overwhelming, you can abort the merge process:

This command stops the merge and returns your branch to its previous state, allowing you to reconsider your approach.

Keeping Commits Small and Focused

To reduce conflicts, encourage a practice of keeping commits small and focused. This means making changes in discrete, logical chunks and merging them often. Smaller changes are less likely to overlap, making conflicts less frequent.

Communicating with Your Team

When working in a team, communication is key. Regularly discuss changes and coordinate efforts, especially when working on shared files. This can significantly reduce the likelihood of conflicts.

Now that you understand how to resolve merge conflicts effectively, you are ready to explore the various merge strategies Git offers.

In the next chapter, we will look at how different strategies can affect your workflow and the outcomes of your merges. You’ll gain insights into choosing the right strategy for your project's needs, ensuring smooth collaboration among team members.