A Git conflict occurs when two branches have changed the same lines of the same file in incompatible ways, and Git can't automatically determine which version to keep during a merge, rebase, or cherry-pick.
Key Points: • Git detects the overlap and pauses the operation instead of guessing, marking the conflicting sections directly in the affected files. • Conflict markers <<<<<<<, =======, and >>>>>>> delimit "your" version, the divider, and the incoming version. • Resolving a conflict means editing the file to keep the correct content, removing the markers, then staging the file with git add. • Conflicts most often happen during merges and rebases, but can also occur during cherry-picks or applying a stash. • Frequent, smaller commits and pulling changes often reduces how large and tangled conflicts become over time.
Example: Two developers both edit the same line of a config file's timeout value on different branches; when one merges into the other, Git can't decide which value is correct and stops, leaving conflict markers in the file for a human to resolve.
Code Example:
<<<<<<< HEAD
timeout = 30
=======
timeout = 60
>>>>>>> feature-branchInterview Tip: A concise interview answer is:
"A conflict happens when two branches change the same lines of a file differently and Git can't auto-merge them. It marks the conflicting sections with markers, and I resolve it by editing the file to keep the correct content, then staging it with git add before continuing."