Lesson 11 of 14 · 19m
Conflicts Are Three Files: markers, diff3, ours/theirs
Read stage 1/2/3 in the index, turn on diff3, survive the rebase ours/theirs flip, and let rerere remember.
When a merge or rebase stops on a conflict, git hasn't failed — it's asked a question it refuses to guess at. It loaded three versions of the file: the merge base (what the file looked like when your branches diverged), ours (your HEAD), and theirs (the incoming side). Hunks that changed on only one side apply cleanly. Hunks both sides rewrote become markers, and the index holds the file three times until you answer.
See the three versions
git ls-files -u during a conflict shows the index holding stage 1 (base), stage 2 (ours), stage 3 (theirs) entries for the path — resolution is literally "produce one stage-0 entry and git add it."
The default marker view shows only ours and theirs:
<<<<<<< HEAD
return session.ttl * 2;
=======
return session.ttl + grace;
>>>>>>> feature/session-extendSet git config --global merge.conflictStyle diff3 and a third section appears — ||||||| shows the base version both sides started from. Base is the whole game: seeing that both sides changed ttl * 2 tells you the correct answer might be ttl + grace multiplied, or something neither side wrote. Without it you're choosing between two texts; with it you're reconciling two intents. Git 2.35 added zdiff3, which trims the common lines out of the markers for an even tighter view.
The tools
git checkout --ours <path>/--theirs <path>— take one side wholesale when the resolution is "theirs wins" or "mine wins."git checkout -m <path>— recreate the conflict markers after a botched resolve.git mergetool— opens your configured 3-way tool (vimdiff, Beyond Compare, etc.) on base/ours/theirs.git diffmid-conflict shows the combined diff — both sides' changes against what you'd get.git merge --abort/git rebase --abort/git cherry-pick --abort— every sequencer state has a fire escape that returns you to the start.
The ours/theirs flip that wastes afternoons
During a merge, ours is your branch, theirs is incoming — intuitive. During a rebase, you're replaying your commits onto someone else's base: "ours" is the branch you're rebasing onto and "theirs" is your own commit being replayed. git checkout --ours mid-rebase grabs main's version, not yours. The number of people who've resolved a rebase conflict backwards and shipped it is why this paragraph exists — the rule is "ours = where HEAD is standing," and during rebase HEAD is standing on the reconstructed base.
rerere: resolve it once
git config --global rerere.enabled true turns on reuse recorded resolution: git snapshots each conflict and your resolution in .git/rr-cache/, and replays it automatically the next time the same conflict appears. It's the difference between fighting a long-lived branch's merge once and fighting it every week — kernel maintainers lean on it heavily for repeated merges, and it turns rebase's per-commit conflict repetition into a one-time cost. git rerere status and git rerere diff show what it recorded.
Practice
- Resolve while thinking, not while merging as fast as possible — a conflict settled by picking one side is a silent revert of the other. Read the base section, decide what the combined intent is, write it, then run the tests on the merged result.
- Keep conflicts rare: rebase personal branches before merge day. A conflict between branches a day apart is a question; between branches a quarter apart is archaeology.
git diff --checkbefore committing the resolution — it flags leftover markers and whitespace sins; CI catching<<<<<<<inmainmeans someone skipped it.
Pitfalls
git checkout --theirsduring a rebase grabs the upstream version — the flip above, in flag form.- "Both changes" resolutions need a compile + test; hunks that don't textually overlap can still break each other semantically (a renamed function, a changed signature).
git mergetoolleaves.origbackups behind by default —git config mergetool.keepBackup falseor remember to clean them.
Try this
Scratch repo: make both branches change the same function, git merge, set merge.conflictStyle diff3, rerun after git merge --abort. Resolve with the base section visible, git ls-files -u empty, then git add and commit.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
What is Git? The Version Control System Every Developer Uses
Git tracks every change to every file in your codebase, lets multiple developers work simultaneously without overwriting each other, and gives you a complete history you can rewind to any point. It is the foundation of modern software development. Here is how it actually works.
VSCode 1.72: Git Source Control has some good enhancements.
The latest version of Microsoft’s Visual Studio Code code editor focuses on improvements to the toolbar and autoscrolling, as well as Git repos. Unveiled October 6, Visual Studio Code 1.72 is also known as the September 2022 release, as it features fixes and features from last month. Toolbar
Apple's WebKit comes to GitHub
The development of WebKit, the open source web browser engine at the heart of Apple’s Safari web browser, has migrated over to GitHub. The WebKit project team announced August 31 that the project had frozen its Subversion tree on June 23 and transitioned management and interaction with the source
GitHub Open Sources Entitlements IAM
GitHub is making available a new IAM (Identity and Access Management) tool, dubbed Entitlements, which leverages the company's own Git framework to parse, track and approve access to a business' systems. The basic idea of Entitlements is to use a dedicated Git repository as a way to provide a…