What is a merge conflict, and how do you resolve it?
BeginnerConceptBranching, versioning & releases
Answer
In one line: A merge conflict happens when two branches change the same lines of a file (or one deletes a file the other changed), and Git can't decide which version to keep — so a person has to choose.
What it looks like:
<<<<<<< HEAD
replicas: 3
=======
replicas: 5
>>>>>>> feature/scale-up
- Between
<<<<<<<and=======: your current branch's version. - Between
=======and>>>>>>>: the incoming branch's version.
How to resolve it:
- Update your branch:
git fetchthengit merge origin/main(orgit rebase origin/main). - Git lists the conflicted files (
git status). - Open each file, decide the correct final content (yours, theirs, or a combination), and remove the markers.
- Mark it resolved:
git add <file>. - Finish:
git commit(for a merge) orgit rebase --continue(for a rebase). - Run the tests again — a cleanly resolved conflict can still break the logic.
- Push and let CI run.
If you get lost: git merge --abort or git rebase --abort takes you back to before you started.
How to avoid conflicts:
- Small, short-lived branches and frequent merges from main.
- Communicate when several people work on the same file.
- Split big files and configs into smaller ones.
- Use formatters so style changes don't create conflicts.
DevOps example: two engineers change the same Helm values.yaml — one updates the image tag, the other the memory limit. Both changes are needed, so the resolved file keeps the new tag and the new limit.
Tip for interviews: explain the steps and mention running tests after resolving — many candidates forget that.
More on Branching, versioning & releases
What is a branching strategy, and why does it matter?BeginnerWhat is trunk-based development?BeginnerWhat is GitFlow, and when would you use it?BeginnerWhat is semantic versioning?BeginnerWhat is a Git tag, and how are tags used in releases?BeginnerWhat is a pull request, and what makes a good code review?Beginner