LearnThatStack Ace your next interview
Git & Version Control · question
Question 6 of 54

How do you resolve a merge conflict, step by step, without panicking?

beginner
← All Git & Version Control questions
Re-explain

Find the conflicted files, edit each one into the version you want, then git add them and commit. A merge conflict only means both branches changed the same lines. Git stops, keeps both versions in the file, and waits for you to decide. Nothing is lost.

Run git status first. It lists the conflicted files under Unmerged paths. Open each one. Your side sits between <<<<<<< HEAD and =======. The incoming side follows, up to >>>>>>> branch-name.

Edit the file into the text you want, then delete all three marker lines. Often the right result keeps parts of both sides.

git status               # which files are unmerged
git add src/config.js    # staging a file marks it resolved
git commit               # finishes the merge
git merge --abort        # bail out, back to before the merge

There is no separate "resolve" command. git add is the signal. Run the build and tests before committing, because a file with no markers left can still be broken. If it goes wrong, git merge --abort before the commit puts everything back as it was.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Git & Version Control One question at a time. Answer out loud, get graded, see what you missed.
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

  • Why does Git flag some overlapping edits as conflicts but merge others cleanly? Names the merge base. Git compares each side to the common ancestor, and only a region both sides changed becomes a conflict.
  • How does resolving a conflict during a rebase differ from resolving one during a merge? Conflicts come one replayed commit at a time. Resolve, git add, then git rebase --continue. Ours and theirs swap, and git rebase --abort bails out.
  • How do you keep one side's version of a whole file without editing the markers by hand? Mentions git checkout --ours or --theirs on the path, then git add, after checking the other side's change really isn't needed.
  • You already committed a bad merge resolution. How do you fix it? Asks whether it was pushed. If not, reset to the pre-merge commit. If it is shared, use git revert -m 1 or commit a fix on top.
  • The same conflict comes back every time you rebase a long branch. What helps? Names git rerere, which records how you resolved a hunk and applies that resolution again when the same conflict shows up.

What you can say

  1. A merge conflict just means both branches changed the same lines, so Git stops, keeps both versions in the file, and waits for me to decide. Nothing is lost.
  2. First I run git status, which lists the conflicted files under Unmerged paths.
  3. In each file, my side sits between the HEAD marker and the row of equals signs, and the incoming side runs from there down to the branch-name marker.
  4. I edit the file into the text I want, often keeping parts of both sides, and delete all three marker lines.
  5. There's no separate resolve command. git add marks the file resolved, and git commit finishes the merge.
  6. A file with no markers can still be broken, so I run the build and tests before committing, and if it goes wrong, git merge --abort puts everything back.

Weak answers to avoid

  • Reaches for reset --hard or a fresh clone That throws work away out of panic. Say that nothing is lost and that git merge --abort before the commit is the clean way back.
  • Takes one side wholesale every time Blindly keeping ours or theirs can drop the other branch's change. Say you read both sides and often keep parts of each.
  • Commits as soon as the markers are gone A file with no markers can still fail to build or break tests. Say you run the build and tests before you commit.
  • Can't say how Git knows a file is resolved There is no resolve command. Staging the file with git add marks it resolved, and git commit then finishes the merge.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Git & Version Control cheatsheet.

← Back to all Git & Version Control questions
Pro · $10/mo

47 of 54 Git & Version Control answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime