glossaryGit Merge Conflict
A situation where git cannot automatically reconcile two divergent changes to the same part of a file, requiring manual resolution by the developer.
explanation
Merge conflicts occur when two branches modify the same line of a file differently, or when one branch deletes a file while the other modifies it. Git marks the conflicting region in the file with conflict markers (<<<<<<<, =======, >>>>>>>) showing both versions, and the developer must edit the file to produce the correct final state before staging and committing the resolution. Conflict resolution is a manual, context-sensitive process. The developer examines both versions, considers the intent of each change, and produces a merged result that satisfies both purposes. This may involve choosing one side, combining elements from both, or writing entirely new code. Tools like mergetool (vimdiff, meld, Beyond Compare) provide three-way merge views showing the base, local, and remote versions. The frequency of merge conflicts is a measure of team coordination and code architecture. Well-modularised codebases where teams work on distinct files experience fewer conflicts. Frequent conflicts in the same files often indicate poor separation of concerns or insufficient communication about ongoing work.
examples
# Conflict markers in a file<<<<<<< HEADconst TIMEOUT = 5000;=======const TIMEOUT = 30000;>>>>>>> feature/timeout-configgit merge --abort # abort the merge and return to pre-merge stategit diff --name-only --diff-filter=U # list unmerged filesgit mergetool # launch the configured merge toolhow git-agent helps
git-agent reduces merge conflicts by producing atomic commits that are scoped to specific files and logical changes. Smaller, focused commits are less likely to touch the same lines as other work, and when conflicts do occur, the clear commit messages help you understand the intent of each side's change.
brew install gitagenthq/brew/git-agentFAQ
Can git-agent resolve merge conflicts automatically?What is the best strategy to avoid merge conflicts?What is the difference between a merge conflict and a rebase conflict?