Git & GitHub Interview Question #42

How do you resolve a merge conflict?

Remotes, Fetch, Pull, Push, Merge, Conflicts, Rebase & Stash Mid-Level Intermediate

Quick Interview Answer

First inspect git status to identify conflicted files. Open each file, understand both versions, and edit it into the correct final result. Conflict markers such as <<<<<<<, =======, and >>>>>>> must not remain unless they are intentionally part of the file content.

Detailed Explanation

First inspect git status to identify conflicted files. Open each file, understand both versions, and edit it into the correct final result. Conflict markers such as <<<<<<<, =======, and >>>>>>> must not remain unless they are intentionally part of the file content.

After resolving a file, stage it with git add. When all conflicts are resolved, complete the merge with git commit or the appropriate continuation command. Build and test the merged result before publishing it.

Code Example

git status

# Edit and resolve the conflicted files
git add Controllers/HomeController.cs
git add Views/Home/Index.cshtml

git commit -m "Resolve merge conflicts"
git status