Progress:
TIER 3 · MODULE 08· Expert

git merge-index

How merges actually wire conflicts into the index.

🎯 What & why

git merge-index walks unmerged entries in the index and runs a merge program for each, letting you script how stage 1/2/3 entries get reconciled. It's the dispatcher under git merge.

🧠 Mental model

After a merge attempt, the index holds up to three stages per conflicted path. merge-index feeds those stages plus the path to a per-file merge driver and updates the index based on its result.

🛠️ Synopsis

git merge-index [-o] [-q] <merge-program> (-a | [--] <file>...)
git merge-index [-o] [-q] <merge-program> --stdin [-z]

🎚️ Switches & options

FlagWhat it does
<merge-program>Program to invoke per file; gets stages and path as arguments.
-a / --allRun the merge program for every unmerged entry in the index.
-q / --quietDon't complain when the merge program exits non-zero.
-o / --one-shotContinue past failures and report at the end instead of stopping on first error.
--stdinRead paths to merge from stdin instead of arguments.
-zWith --stdin, expect NUL-terminated paths.

💡 Use cases

🧪 Examples

Run git's default driver on all conflicts
git merge-index -o git-merge-one-file -a
Resolve a single file via custom driver
git merge-index ./my-driver.sh -- path/to/conflicted
Stream paths from stdin (NUL-separated)
git diff --name-only -z --diff-filter=U | git merge-index -o git-merge-one-file --stdin -z
Quiet, keep going on errors
git merge-index -q -o git-merge-one-file -a

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

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