October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Resolve a Three-Way Merge Conflict from the Linux Command Line

A terminal workflow for inspecting Git’s three conflict versions, editing the intended result, staging resolved paths, and completing or aborting a merge.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To resolve a three-way Git merge conflict in a Linux terminal, inspect the unmerged paths with git status, compare the base and both branch versions, edit each conflicted file into the intended final form, and stage it with git add. Finish with git merge --continue or git commit; use git merge --abort if you need to abandon the merge.

What makes a merge conflict three-way?

Git compares three versions of the relevant content: a common ancestor (the base), the current branch, and the branch being merged in. A conflict occurs when Git cannot combine the changes automatically. In the index, an unresolved path can expose those versions as stage 1 (base), stage 2 (current HEAD), and stage 3 (MERGE_HEAD, the other side).

As an Amazon Associate I earn from qualifying purchases.

For a text conflict, the working-tree file often contains markers such as <<<<<<<, =======, and >>>>>>>. These show competing content, not a decision about which content is correct. Your resolution is the final content you write into the file.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Resolve and complete the merge from the terminal

  1. List unresolved paths. Run git status. Look for paths reported as unmerged; resolve each one rather than assuming the first conflict is the only one.

  2. Inspect the conflict and surrounding context. Open each path in an editor. Read the full relevant function, paragraph, or configuration—not just the marker-delimited lines. Preserve the intended changes from either or both branches, remove the conflict markers, and save valid final content.

  3. Compare the three versions if needed. For a conflicted path, inspect the index entries with git show :1:path/to/file for the base, git show :2:path/to/file for the current branch, and git show :3:path/to/file for the incoming branch. Replace path/to/file with the actual path.

    Git also documents git diff for viewing a three-way comparison of current and merged-in versions. Where the AUTO_MERGE ref is available, git diff AUTO_MERGE shows textual resolution work performed so far. To review commits from either side that touched an unresolved path, use git log --merge -p -- path/to/file.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Stage the resolved path. Run git add path/to/file for each file whose final content is ready. Staging tells Git to record your resolution; it is not merely a note that you looked at the file.

  5. Review, then finish. Check git status and review the resulting changes with git diff --cached. Run the project’s appropriate checks when applicable. When all conflicts are resolved and staged, run git merge --continue or git commit to complete the merge. git merge --continue verifies that a merge is in progress before proceeding to commit.

Choose the correct content, not simply one side

Do not accept everything between one marker and the separator—or everything below it—without understanding what each branch changed. A valid resolution may combine both changes, keep one, or deliberately replace both with a third result. Check surrounding code or text and project behavior; removing markers only makes the file syntactically cleaner, not necessarily correct.

Also distinguish the -Xours strategy option from the ours merge strategy. The ort strategy option -Xours favors the current side for conflicting hunks while retaining non-conflicting changes from the other tree. The ours strategy ignores the other tree’s contents entirely. These are different choices, and neither is a general substitute for reviewing the merge.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When the conflict is not a simple text block

Git can report file-level conflicts or conflicts involving submodules, where editing marker blocks is not the whole resolution. Use git status to identify the path’s state and inspect the path-specific differences before choosing what to keep. Once the path has the intended result, stage it with git add as appropriate.

Use a merge tool if it helps

git mergetool can launch a configured external utility after a merge. Run it without path arguments to process conflicted files. Utilities such as meld, vimdiff, and kdiff3 are examples, but availability depends on what is installed and configured on your system. Manual editing and Git’s diff commands are sufficient; no external tool is required.

For a custom tool, Git can provide temporary BASE, LOCAL, and REMOTE inputs when available, and expects the tool to write the resolved result to MERGED. Regardless of the interface, inspect the final file and review the staged diff before completing the merge.

Abort if you need to abandon the merge

Run git merge --abort to attempt to return to the state before the merge began. Git warns that it may not be able to reconstruct all prior changes if you had uncommitted work before the merge, particularly if that work was further modified while resolving conflicts. Starting a merge with a clean working tree when practical reduces this risk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.