Back
GitoryxGitoryx
Beginner12 min read

How to Resolve Merge Conflicts in Git

Merge conflicts are one of the most common pain points for Git users. This guide walks you through every step: detecting, understanding, and resolving conflicts — whether you prefer the CLI or a visual Git GUI like Gitoryx.

The Problem

You run `git merge` or `git pull` and Git stops dead: "CONFLICT (content): Merge conflict in src/app.js". Your terminal is frozen, your files are filled with `<<<<<<<` markers, and you have no idea which version to keep. Sound familiar?

Merge conflicts happen every day in collaborative development — any time two developers edit the same lines of code. Knowing how to resolve them quickly and safely is a core Git skill. Getting it wrong means corrupting shared code or losing work.

Common mistakes developers make with this:

  • Accepting all incoming changes without reading them
  • Forgetting to remove conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) before committing
  • Committing in a conflicted state
  • Aborting the merge when a simple resolution was possible

Gitoryx: Gitoryx shows conflicts visually — every conflicted file is highlighted with a warning badge, and a side-by-side diff editor lets you choose which version to keep (or combine both) in one click.

What is Resolve Merge Conflicts in Git?

A merge conflict occurs when Git cannot automatically reconcile changes from two branches because both modified the same lines of a file. Git pauses the merge and asks you to manually choose which changes to keep.

Step-by-Step Guide

1

Understand what triggered the conflict

A conflict usually happens after `git merge`, `git rebase`, or `git pull`. When Git encounters incompatible changes, it marks the conflicted files and pauses the operation.

bash
# Attempt a merge
git merge feature/login

# Git output when a conflict occurs:
# Auto-merging src/auth.js
# CONFLICT (content): Merge conflict in src/auth.js
# Automatic merge failed; fix conflicts and then commit the result.

Run `git status` immediately after a conflict to see which files need resolution.

2

Identify all conflicted files

Use `git status` to list every file in a conflicted state. Look for `both modified` in the output.

bash
git status

# Output:
# On branch main
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#         both modified:   src/auth.js
3

Open the conflicted file and read the markers

Git inserts conflict markers directly into the file. The section between `<<<<<<<` and `=======` is your current branch's version. The section between `=======` and `>>>>>>>` is the incoming branch's version.

javascript
<<<<<<< HEAD
function login(user) {
  return authenticate(user, { timeout: 5000 });
}
=======
function login(user, options = {}) {
  return authenticate(user, options);
}
>>>>>>> feature/login

HEAD is always your current branch. The label after `>>>>>>>` is the branch being merged in.

4

Resolve the conflict

Edit the file to keep the version you want — or combine both. Delete all three conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) and leave only clean, valid code.

javascript
// Resolved version — combining both approaches:
function login(user, options = { timeout: 5000 }) {
  return authenticate(user, options);
}

Never commit a file that still contains `<<<<<<<`, `=======`, or `>>>>>>>` markers. Your code will break.

See this workflow in Gitoryx — Gitoryx screenshot

See this workflow in Gitoryx. Conflicted files are highlighted with a warning badge in the file tree — no need to hunt through `git status` output.

Free download
5

Stage the resolved file

Once you've resolved and saved the file, tell Git the conflict is fixed by staging it with `git add`.

bash
git add src/auth.js

# Verify all conflicts are resolved:
git status
# Should show: "All conflicts fixed but you are still merging."
6

Complete the merge with a commit

After all conflicts are resolved and staged, finish the merge by creating a commit. Git will pre-fill a merge commit message.

bash
git commit
# Git opens your editor with a default message like:
# "Merge branch 'feature/login' into main"
# Save and close to complete the merge.

If you want to abort the entire merge and go back to your pre-merge state, run `git merge --abort` before committing.

7

Verify the result

Check your commit history to confirm the merge completed correctly.

bash
git log --oneline --graph -6

# Expected output shows a merge commit:
# *   a3f1c2d Merge branch 'feature/login' into main
# |\
# | * 9b2e4f1 Add flexible login options
# * | 7c3d5a8 Add login timeout
# |/
# * 1a2b3c4 Initial auth setup

Common Mistakes to Avoid

Leaving conflict markers in the file

The most common mistake — committing code that still contains `<<<<<<<`, `=======`, or `>>>>>>>` markers. This breaks your application immediately.

Fix: Always run `git diff --check` before committing. It flags any remaining conflict markers.

Using `git checkout` to wipe both versions

Running `git checkout -- file.js` during a conflict discards both the current and incoming changes, losing the merge entirely.

Fix: Use `git checkout --ours file.js` to keep your version, or `git checkout --theirs file.js` to keep the incoming version — only if you're sure.

Committing without staging all resolved files

If you resolved three conflicted files but only staged two, `git commit` will fail or create a partial merge.

Fix: Always run `git status` before committing to confirm every conflict is resolved and staged.

Ignoring why the conflict happened

Blindly accepting one side without understanding both changes often introduces logic bugs that are hard to trace.

Fix: Read both versions carefully. Talk to the developer who made the incoming changes if you're unsure which version is correct.

Gitoryx — visual Git client for macOS, Windows & Linux
GitoryxGitoryx — macOS, Windows & Linux

Resolve Merge Conflicts Visually in Gitoryx

  • Conflicted files are highlighted with a warning badge in the file tree — no need to hunt through `git status` output.
  • The built-in conflict editor shows a three-panel view: your version, the incoming version, and the merged result.
  • Click to accept your changes, incoming changes, or both with a single click — no manual marker deletion.
  • Gitoryx validates that no conflict markers remain before letting you commit, preventing the most common mistake.
  • The visual commit graph shows the merge point and both branch histories side by side.
Download Gitoryx — FreemacOS · Windows · Linux · No subscription

Frequently Asked Questions

What causes a merge conflict in Git?

A merge conflict occurs when two branches modify the same lines of the same file, or when one branch deletes a file that another branch modified. Git cannot determine which version to keep, so it pauses and asks you to decide.

How do I abort a merge and go back to my previous state?

Run `git merge --abort` at any point during an unfinished merge. This resets your working directory to the state it was in before the merge started.

What do the conflict markers mean?

`<<<<<<< HEAD` marks the start of your current branch's version. `=======` separates the two versions. `>>>>>>> branch-name` marks the end of the incoming branch's version. Everything between these markers must be resolved manually.

Can I accept one side of a conflict automatically?

Yes. Use `git checkout --ours filename` to keep your version, or `git checkout --theirs filename` to keep the incoming version entirely. Only do this when you're certain which version is correct.

How do I prevent merge conflicts?

Pull frequently from the main branch to keep your feature branch up to date (`git pull origin main`). Communicate with your team about which files you're working on. Keep branches short-lived and focused on a single feature.

What is a merge tool in Git?

A merge tool is an external editor or built-in interface that displays conflicted files side by side, making it easier to compare and choose between versions. Configure one with `git config --global merge.tool <toolname>` or use a visual Git client like Gitoryx.

What happens if I commit with unresolved conflict markers?

Git will allow it (unless prevented by a hook), but your code will contain raw conflict marker text, breaking any file that is parsed — JavaScript, CSS, JSON, etc. Always run `git diff --check` before committing.

Does git rebase also cause merge conflicts?

Yes. Rebasing re-applies commits one at a time, so you may get a conflict at each commit. Resolve the conflict, run `git add`, then continue with `git rebase --continue`. Run `git rebase --abort` to cancel.

See it in action with Gitoryx

Everything in this tutorial is faster and clearer with a visual Git client. Gitoryx is free, runs natively on macOS, Windows, and Linux, and built for developers who want to move fast without breaking things.