{"id":"l-git-2-3","courseId":"git-github","lang":"en","kind":"lesson","summary":"Read a merge conflict calmly, edit the conflict markers into the result you want, mark files resolved and finish the merge, or abort it and start over.","html":"<p>Sooner or later two branches change the same line. You change your tagline on <code dir=\"ltr\">main</code> to “Front-end developer in Lagos.” while your <code dir=\"ltr\">tagline</code> branch, started earlier, rewrote the same line to “Front-end developer who loves accessible UI.” Git can’t know which is right, so it stops and asks. That’s all a merge conflict is: a question. I’ve helped hundreds of people through their first one, and the panic always comes from the unfamiliar markers, never from the actual problem.</p>\n<h2 id=\"sec-1\" tabindex=\"-1\">What Git tells you</h2>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"0\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> switch</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> main</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> merge</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> tagline</span></span></code></pre></div>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"1\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>Auto-merging index.html\nCONFLICT (content): Merge conflict in index.html\nAutomatic merge failed; fix conflicts and then commit the result.</code></pre></div>\n<p>You’re now <em>in the middle of a merge</em>. Any files that merged cleanly are already staged. Run <code dir=\"ltr\">git status</code> to see the rest:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"2\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>On branch main\nYou have unmerged paths.\n  (fix conflicts and run &quot;git commit&quot;)\n  (use &quot;git merge --abort&quot; to abort the merge)\n\nUnmerged paths:\n  (use &quot;git add &lt;file&gt;...&quot; to mark resolution)\n\tboth modified:   index.html\n\nno changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)</code></pre></div>\n<p>Read that output; it’s the whole procedure. Fix the conflicts, mark each file resolved with <code dir=\"ltr\">git add</code>, then <code dir=\"ltr\">git commit</code>. Or abort.</p>\n<h2 id=\"sec-2\" tabindex=\"-1\">Reading the markers</h2>\n<p>Open <code dir=\"ltr\">index.html</code>. Git has written both versions into the file, fenced by markers:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"html\" data-index=\"3\"><div class=\"code-head\"><span class=\"code-title\">index.html</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Maya Okafor&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#82071E;--shiki-light-font-style:italic;--shiki-dark:#FFA198;--shiki-dark-font-style:italic\">&#x3C;&#x3C;&#x3C;&#x3C;&#x3C;&#x3C;&#x3C;</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\"> HEAD</span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Front-end developer in Lagos.&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">=======</span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Front-end developer who loves accessible UI.&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>>>>>>> tagline</span></span></code></pre></div>\n<ul>\n<li>The top half, from the opening marker labelled <code dir=\"ltr\">HEAD</code> down to <code dir=\"ltr\">=======</code>, is <strong>your side</strong>: the branch you’re on, here <code dir=\"ltr\">main</code>.</li>\n<li>The bottom half, from <code dir=\"ltr\">=======</code> down to the closing marker labelled <code dir=\"ltr\">tagline</code>, is <strong>their side</strong>: the branch you’re merging in.</li>\n</ul>\n<p>Everything outside the markers merged without trouble. A file can contain several of these blocks, so search the file for the opening marker (seven less-than signs) until there are none left.</p>\n<figure class=\"diagram\"><svg class=\"diagram-svg\" focusable=\"false\" viewBox=\"0 0 700 250\" role=\"img\" aria-labelledby=\"l-git-2-3-t1\"><defs><marker id=\"arrow-l-git-2-3-1\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto-start-reverse\"><path d=\"M0 0 L10 5 L0 10 z\" class=\"d-arrowhead\"/></marker></defs>\n  <title id=\"l-git-2-3-t1\">The merge base says 'Front-end developer in progress.' Main changed it to 'in Lagos.' The tagline branch changed it to 'who loves accessible UI.' Both sides changed the same line, so Git cannot choose and you write the result by hand.</title>\n  <rect class=\"d-box\" x=\"230\" y=\"15\" width=\"240\" height=\"56\" rx=\"10\"/>\n  <text class=\"d-label-strong\" x=\"350\" y=\"38\" text-anchor=\"middle\">Merge base</text>\n  <text class=\"d-label-muted\" x=\"350\" y=\"60\" text-anchor=\"middle\">\"…developer in progress.\"</text>\n  <rect class=\"d-box-accent\" x=\"20\" y=\"105\" width=\"270\" height=\"56\" rx=\"10\"/>\n  <text class=\"d-label-strong\" x=\"155\" y=\"128\" text-anchor=\"middle\">HEAD (main)</text>\n  <text class=\"d-label-muted\" x=\"155\" y=\"150\" text-anchor=\"middle\">\"…developer in Lagos.\"</text>\n  <rect class=\"d-box-accent\" x=\"410\" y=\"105\" width=\"270\" height=\"56\" rx=\"10\"/>\n  <text class=\"d-label-strong\" x=\"545\" y=\"128\" text-anchor=\"middle\">tagline</text>\n  <text class=\"d-label-muted\" x=\"545\" y=\"150\" text-anchor=\"middle\">\"…loves accessible UI.\"</text>\n  <path class=\"d-arrow\" d=\"M300 71 L190 103\" marker-end=\"url(#arrow-l-git-2-3-1)\"/>\n  <path class=\"d-arrow\" d=\"M400 71 L510 103\" marker-end=\"url(#arrow-l-git-2-3-1)\"/>\n  <rect class=\"d-box-warn\" x=\"190\" y=\"190\" width=\"320\" height=\"50\" rx=\"10\"/>\n  <text class=\"d-label-strong\" x=\"350\" y=\"220\" text-anchor=\"middle\">Same line changed twice: you decide</text>\n  <path class=\"d-arrow\" d=\"M155 161 L260 188\" marker-end=\"url(#arrow-l-git-2-3-1)\"/>\n  <path class=\"d-arrow\" d=\"M545 161 L440 188\" marker-end=\"url(#arrow-l-git-2-3-1)\"/>\n</svg><figcaption>Git compares both sides with the merge base</figcaption></figure>\n<h2 id=\"sec-3\" tabindex=\"-1\">Resolving it, step by step</h2>\n<p><strong>1. Decide what the result should be.</strong> Not “which side wins” by reflex; what should the page actually say? Often it’s a combination. Here, both facts are good:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"html\" data-index=\"4\"><div class=\"code-head\"><span class=\"code-title\">index.html</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Maya Okafor&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">h1</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span>\n<span class=\"line\"><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">    &#x3C;</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">>Front-end developer in Lagos who loves accessible UI.&#x3C;/</span><span style=\"color:#116329;--shiki-dark:#7EE787\">p</span><span style=\"color:#1F2328;--shiki-dark:#E6EDF3\">></span></span></code></pre></div>\n<p><strong>2. Remove every marker.</strong> The three marker lines must go. Git doesn’t read the file to check; it’s your job.</p>\n<p><strong>3. Check the result.</strong> Open the page in a browser, run your tests (<code dir=\"ltr\">npm test</code> once the portfolio has them), and run:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"5\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> diff</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --check</span></span></code></pre></div>\n<p>It warns about any leftover conflict markers. Five seconds well spent.</p>\n<p><strong>4. Mark it resolved and finish.</strong></p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"6\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> add</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> index.html</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> status</span><span style=\"color:#6E7781;--shiki-dark:#8B949E\">        # \"All conflicts fixed but you are still merging.\"</span></span>\n<span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> commit</span><span style=\"color:#6E7781;--shiki-dark:#8B949E\">        # editor opens with \"Merge branch 'tagline'\"; save and close</span></span></code></pre></div>\n<p><code dir=\"ltr\">git merge --continue</code> does the same as that final <code dir=\"ltr\">git commit</code>. The merge commit now has two parents, like any other.</p>\n<p>If you know one side should win for a whole file, skip the editing: <code dir=\"ltr\">git restore --ours index.html</code> keeps your branch’s version and <code dir=\"ltr\">git restore --theirs index.html</code> keeps the incoming one. Then <code dir=\"ltr\">git add</code> it as usual.</p>\n<aside class=\"callout callout-mistake\" role=\"note\"><p class=\"callout-title\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3\"/><path d=\"M12 9v4\"/><path d=\"M12 17h.01\"/></svg><span><span class=\"callout-kind\">Common mistake</span><span class=\"callout-sep\" aria-hidden=\"true\"> · </span>Committing the markers</span></p>\n<p>The most common conflict bug isn’t a wrong choice; it’s a stray <code dir=\"ltr\">=======</code> or closing marker line committed into the file, sometimes all the way to production. Git won’t stop you, because to Git it’s just text. Make <code dir=\"ltr\">git diff --check</code> and actually viewing the page part of every resolution.</p>\n</aside>\n<h2 id=\"sec-4\" tabindex=\"-1\">Bailing out</h2>\n<p>If a conflict is bigger than you expected, or you merged the wrong branch, you can always retreat:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"7\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> merge</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --abort</span></span></code></pre></div>\n<p>Your branch, index and files go back to exactly how they were before <code dir=\"ltr\">git merge</code>. Nothing is lost. It’s often smart to abort, update or tidy the branch, and try again with a clear head.</p>\n<p>The same markers and the same fix-add-continue routine appear whenever Git combines two versions of a line: during a rebase, when you apply a stash, and when <code dir=\"ltr\">git pull</code> merges someone else’s work into yours. Learn the routine once here and every later conflict in this course will look familiar. Only the command you use to continue or abort changes.</p>\n<h2 id=\"sec-5\" tabindex=\"-1\">Making conflicts easier to read</h2>\n<p>By default you see only the two sides. Ask Git to show the original lines too:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"bash\" data-index=\"8\"><div class=\"code-head\"><span class=\"code-title\">Terminal</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color:#953800;--shiki-dark:#FFA657\">git</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> config</span><span style=\"color:#0550AE;--shiki-dark:#79C0FF\"> --global</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> merge.conflictStyle</span><span style=\"color:#0A3069;--shiki-dark:#A5D6FF\"> zdiff3</span></span></code></pre></div>\n<p>Now each conflict has a third section between <code dir=\"ltr\">|||||||</code> and <code dir=\"ltr\">=======</code> showing the merge base. Seeing what the line was <em>before</em> either change usually makes the right answer obvious: you can see what each side meant to do, not only what it ended up with.</p>\n<p>Editors help too. VS Code highlights each block with buttons such as Accept Current Change, Accept Incoming Change and Accept Both Changes, plus a three-way merge editor. Use them, but read the result; Accept Both often produces two <code dir=\"ltr\">&lt;p&gt;</code> tags where you wanted one.</p>\n<aside class=\"callout callout-tip\" role=\"note\"><p class=\"callout-title\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><path d=\"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5\"/><path d=\"M9 18h6\"/><path d=\"M10 22h4\"/></svg><span><span class=\"callout-kind\">Tip</span><span class=\"callout-sep\" aria-hidden=\"true\"> · </span>Fewer, smaller conflicts</span></p>\n<p>Conflicts grow with time and branch size. Keep branches short-lived, merge them soon, and bring <code dir=\"ltr\">main</code> into a long-running branch every day or two rather than once at the end. Two people editing one shared file all week is a conversation to have before the merge, not during it.</p>\n</aside>\n<p>Merging is one way to combine histories. Next you’ll meet the other, rebasing, and the one rule that keeps it safe.</p>\n","toc":[{"id":"sec-1","text":"What Git tells you","level":2},{"id":"sec-2","text":"Reading the markers","level":2},{"id":"sec-3","text":"Resolving it, step by step","level":2},{"id":"sec-4","text":"Bailing out","level":2},{"id":"sec-5","text":"Making conflicts easier to read","level":2}],"takeaways":["A conflict means both branches changed the same lines since their merge base, so Git asks you to choose; nothing is lost or broken.","Between <code dir=\"ltr\">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> and <code dir=\"ltr\">=======</code> is your current branch (HEAD); between <code dir=\"ltr\">=======</code> and <code dir=\"ltr\">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</code> is the branch being merged in.","Resolve by editing the file into its final form, removing every marker, then <code dir=\"ltr\">git add</code> the file and <code dir=\"ltr\">git commit</code>.","<code dir=\"ltr\">git merge --abort</code> puts everything back exactly as it was before the merge started.","Setting <code dir=\"ltr\">merge.conflictStyle</code> to <code dir=\"ltr\">zdiff3</code> also shows the original lines, which makes most conflicts easy to judge."],"further":[{"title":"Basic Merge Conflicts (Pro Git)","url":"https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merge_conflicts"},{"title":"Resolving a merge conflict using the command line","url":"https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/resolving-a-merge-conflict-using-the-command-line"},{"title":"git merge, How conflicts are presented","url":"https://git-scm.com/docs/git-merge#_how_conflicts_are_presented"}],"quiz":[{"q":"<p>You’re on <code dir=\"ltr\">main</code> and ran <code dir=\"ltr\">git merge tagline</code>. In <code dir=\"ltr\">index.html</code> you see:</p>\n<div class=\"code-block\" dir=\"ltr\" data-lang=\"text\" data-index=\"0\"><div class=\"code-head\"><span class=\"code-title\">Text</span><span class=\"code-actions\"><button type=\"button\" class=\"code-btn\" data-action=\"copy\" aria-label=\"Copy code\"><svg class=\"icon \" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\" focusable=\"false\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"/><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"/></svg><span>Copy</span></button></span></div><pre class=\"shiki\" tabindex=\"0\"><code>&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD\n&lt;p&gt;Front-end developer in Lagos.&lt;/p&gt;\n=======\n&lt;p&gt;Front-end developer who loves accessible UI.&lt;/p&gt;\n&gt;&gt;&gt;&gt;&gt;&gt;&gt; tagline</code></pre></div>\n<p>Which line came from <code dir=\"ltr\">main</code>?</p>\n","options":[{"text":"The second one, because the branch being merged in always appears first.","why":"It’s the other way round. The top half is always the branch you’re on, labelled HEAD."},{"text":"<code dir=\"ltr\">Front-end developer in Lagos.</code>, because the top half is HEAD, your current branch.","why":"Correct. You’re on <code dir=\"ltr\">main</code>, so HEAD is <code dir=\"ltr\">main</code>. The bottom half, labelled <code dir=\"ltr\">tagline</code>, is what’s being merged in."},{"text":"Neither; both lines are Git’s suggestions for a combined version.","why":"Git doesn’t invent text. Each half is exactly what one branch contains."}],"answer":1},{"q":"<p>You’ve edited <code dir=\"ltr\">index.html</code> so it reads the way you want and every marker is gone. <code dir=\"ltr\">git status</code> still lists it under “Unmerged paths”. What’s the next step?</p>","options":[{"text":"Run <code dir=\"ltr\">git merge tagline</code> again so Git notices the fix.","why":"A merge is already in progress. Starting another one fails; Git is waiting for you to mark files as resolved."},{"text":"Run <code dir=\"ltr\">git commit -a --no-verify</code>.","why":"<code dir=\"ltr\">--no-verify</code> skips hooks and has nothing to do with conflicts. Stage the file and commit normally."},{"text":"Run <code dir=\"ltr\">git add index.html</code> to mark it resolved, then <code dir=\"ltr\">git commit</code>.","why":"Correct. Staging tells Git the conflict is settled. When no unmerged paths remain, <code dir=\"ltr\">git commit</code> creates the merge commit."},{"text":"Delete <code dir=\"ltr\">index.html</code> and run <code dir=\"ltr\">git restore index.html</code>.","why":"That throws away the resolution you just wrote. There’s no reason to delete anything."}],"answer":2},{"q":"<p>Halfway through a messy conflict you realise you merged the wrong branch. How do you get back to exactly where you were before the merge?</p>","options":[{"text":"<code dir=\"ltr\">git merge --abort</code>","why":"Correct. While a merge is in progress, this restores the branch, the index and your files to their state before <code dir=\"ltr\">git merge</code>."},{"text":"<code dir=\"ltr\">git restore .</code>","why":"That discards working-tree changes but leaves Git in the middle of a merge, with the merge state still active."},{"text":"<code dir=\"ltr\">git branch -D main</code>","why":"Deleting the branch you’re on isn’t allowed, and it wouldn’t undo anything."},{"text":"Close the terminal; unfinished merges are cancelled automatically.","why":"The merge state is stored in <code dir=\"ltr\">.git</code>, not in your terminal session. It’s still there when you reopen it."}],"answer":0},{"q":"<p>Your branch has merged and pushed, and a teammate finds <code dir=\"ltr\">=======</code> printed on the live home page. Which habit would have caught this before committing?</p>","options":[{"text":"Running <code dir=\"ltr\">git log --graph</code> after every merge.","why":"The graph shows commit structure, not file contents, so leftover markers wouldn’t appear."},{"text":"Always resolving with <code dir=\"ltr\">git merge --abort</code>.","why":"Aborting cancels the merge instead of resolving it, so the work never lands."},{"text":"Using <code dir=\"ltr\">git commit -m</code> instead of the editor.","why":"The message source has nothing to do with markers inside your files."},{"text":"Running <code dir=\"ltr\">git diff --check</code> (and opening the page) before <code dir=\"ltr\">git add</code>.","why":"Correct. <code dir=\"ltr\">git diff --check</code> warns about leftover conflict markers, and actually viewing the result catches the rest."}],"answer":3}],"exercise":{"kind":"order","items":["merge","status","open","edit","check","add","commit"],"title":"Resolve the tagline conflict","prompt":"<p>You’re on <code dir=\"ltr\">main</code> and want the <code dir=\"ltr\">tagline</code> branch merged in. Put the steps in the order you’d run them to get from the conflict to a finished merge commit.</p>\n","hints":["Git must report the conflict before there’s anything to fix, and <code dir=\"ltr\">git status</code> tells you which files need you.","You fix the file before you check it, and you check it before you tell Git it’s resolved.","The merge commit is always the very last step."],"explanation":"<p>The merge stops at the conflict; <code dir=\"ltr\">git status</code> lists the unmerged files. You open each one, edit it into the final text and delete every marker, then check the result (<code dir=\"ltr\">git diff --check</code>, view the page, run the tests). Only then does <code dir=\"ltr\">git add</code> mark it resolved, and <code dir=\"ltr\">git commit</code> (or <code dir=\"ltr\">git merge --continue</code>) records the merge commit. If anything goes wrong before that last step, <code dir=\"ltr\">git merge --abort</code> returns you to where you started.</p>\n","checkLabels":{},"itemText":{"merge":"Run <code dir=\"ltr\">git merge tagline</code> and see <code dir=\"ltr\">CONFLICT (content): Merge conflict in index.html</code>.","status":"Run <code dir=\"ltr\">git status</code> to list the unmerged paths.","open":"Open <code dir=\"ltr\">index.html</code> and find the <code dir=\"ltr\">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</code> block.","edit":"Write the final tagline and delete the three marker lines.","check":"Run <code dir=\"ltr\">git diff --check</code> and view the page in a browser.","add":"Run <code dir=\"ltr\">git add index.html</code> to mark the conflict resolved.","commit":"Run <code dir=\"ltr\">git commit</code> to record the merge commit."}},"words":741,"readMinutes":4}