Progress:
TIER 3 · MODULE 07· Expert

git merge-file

Merge engine you can drive on arbitrary files outside a repo.

🎯 What & why

git merge-file performs a 3-way merge on three arbitrary files (current, base, other) and writes the result. It's Git's merge engine exposed for scripts and external diff tools.

🧠 Mental model

Think diff3 with conflict markers and Git semantics. No repo required; you point it at three paths and it produces a merged file plus an exit code equal to the number of conflicts.

🛠️ Synopsis

git merge-file [-L <cur> [-L <base> [-L <other>]]] [--ours|--theirs|--union]
               [-p] [-q] [--marker-size=<n>] [--diff-algorithm=<algo>]
               <current-file> <base-file> <other-file>

🎚️ Switches & options

FlagWhat it does
-pWrite the merged result to stdout instead of overwriting <current-file>.
-qQuiet: suppress conflict warnings on stderr.
-L <name>Label for current/base/other (repeat up to 3x); shows up in conflict markers.
--oursOn conflict, take the current side; no markers emitted.
--theirsOn conflict, take the other side; no markers emitted.
--unionConcatenate both sides on conflict; no markers, but may produce nonsense.
--marker-size=<n>Change the length of <<<<<<< markers (default 7).
--diff-algorithm=<algo>Pick myers, minimal, patience, or histogram.

💡 Use cases

🧪 Examples

Standard 3-way merge in place
git merge-file -L mine -L base -L theirs cur.txt base.txt other.txt
Preview to stdout, keep originals
git merge-file -p cur.txt base.txt other.txt
Auto-resolve favoring our side
git merge-file --ours cur.txt base.txt other.txt
Histogram diff for code-like content
git merge-file --diff-algorithm=histogram cur.c base.c other.c

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.