Merge Conflicts
A merge conflict is git declining to guess: two branches changed the same lines, and a person must decide what the text should say. It is the moment beginners fear most, and the one where lazygit's screen earns its keep most plainly — everything about the situation is visible at once, and resolving it is choosing sides, hunk by hunk, with the result staged for you. The outcome: you can take a repository frozen mid-merge, read exactly what is contested, settle each contested block, and conclude the merge — or abandon it cleanly — without opening an editor.
The lab's conflict
The second practice repository,
lazygit-lab/conflict, is frozen in
exactly this state. Its picnic plan began
as "Lunch: soup". One branch changed the
line to salad, another to pasta, both
were merged into main — the first
cleanly, the second not. Build it with
the same script:
bash lazygit-lab/mkfixture.sh
cd lazygit-lab/conflict
lazygit
Reading a frozen merge
The screen announces the situation in
three places (transcript
lazygit-lab/transcripts/t08-conflict.txt):
- The Status panel reads
(merging) conflict → main— you are mid-merge, and it is not going well yet. - The Files panel narrows itself to the
problem: only conflicted files, its
title noting "(only conflicting)". One
row:
UU picnic.txt. The code is git's own — Updated, in both the index and the working tree columns: both branches' versions are present, and neither has won. - The main panel shows the file itself, with the contested block fenced by git's markers:
<<<<<<< HEAD
Lunch: salad
=======
Lunch: pasta
>>>>>>> pasta
Read the fence as a sentence. Between
<<<<<<< HEAD and ======= is your
current branch's version — you are on
main, and main says salad. Between
======= and >>>>>>> pasta is the
incoming version, from the branch being
merged in. Everything outside the fences
agreed, and git has already woven it
together. Your whole job is the fences.
The hint bar has changed, too: its first entry is now View merge options: m, and its right-hand end reads Merging. The program knows what mode it is in.
Resolving, hunk by hunk
Select the conflicted file and press Enter. Focus moves into the main panel's conflict view, and the hint bar becomes the resolution toolkit:
View merge options: m | Pick hunk: <space> | Pick both hunks: b | Previous hunk: <up> | …
The up and down arrows move between contested blocks — hunks — and within a hunk, between its two sides; the selected side is highlighted (in the lab's text captures the highlight is colour, described here in words). The verbs:
- Space — pick this side. The hunk is settled in favour of the highlighted version; the other version and the fence markers leave the file.
b— pick both. Keep both sides, one after the other — for the conflicts that were never really either/or: two items added to the same list, two paragraphs that both belong.z— undo a pick, if you chose with your fingers faster than your judgement; the conflict view has its own small undo for its own small decisions. (In the view's keybindings list, and offered here on that authority: the lab's single hunk was settled in one pick and never needed it.)
The lab's hunk offered salad or pasta;
Space, with the HEAD side selected, kept
salad. The effect was immediate and
larger than the hunk: the Files panel
emptied, the main panel reported "No
changed files", and the command log
showed git add -- picnic.txt —
with the last conflict gone, lazygit
stages the resolution itself. The file on
disk was clean text again, fences and
all removed, checked afterwards with
plain eyes and git status.
What Space cannot do is write: a
conflict whose right answer is a third
text — "Lunch: soup, and bring both
salads" — is not a choice between sides.
For that, the file is yours to edit (the
Files panel's e opens it in your
editor), and lazygit will stage the
result when the markers are gone.
Chapter 16 files this under honest
limits: the conflict view settles
choices; authorship still needs an
author.
Concluding, or abandoning
The merge is not finished when the
conflicts are. The Status panel still
reads (merging), and git's own status
says it exactly: "All conflicts fixed
but you are still merging." Press
m — the Merge options menu:
c— continue: conclude the merge with a commit. The lab chose it, and git's log gained the merge commit,Merge branch 'pasta', with both parents — the conflict closed, the history honest about how.a— abort: call the whole merge off and return the tree to its pre-merge state (git merge --abort). The branches keep their commits; only the attempted union is forgotten.
One honest rough edge, because the lab
hit it and you might: when the lab's
resolution happened to make the file
identical to what HEAD already held —
salad was, after all, already main's own
word — pressing c for an ordinary
commit refused with an error, "No files
staged", because versus HEAD there was
no difference to commit. The merge was
still open and still needed concluding,
and the way out was the m menu's
continue, which concludes a merge
regardless of whether its result differs.
If a "No files staged" ever puzzles you
mid-merge, chapter 17 retells this
story; the short version is: it is about
the emptiness of the difference, not
about the merge, and m is the door.
And Esc, during a merge, is not a way back to browsing: the hint bar names it Abort merge, and it asks — "Are you sure you want to abort the current merge?" — before discarding the attempt. The program treats an unfinished merge as a state you leave decidedly, one way or the other. So does git. The screen simply refuses to let you drift out of it by accident.