WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 19 of 100

How do you resolve merge conflicts in Git?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

In Git, a merge conflict occurs when Git is unable to automatically merge changes from two or more branches. This can happen when two or more branches have made changes to the same file or lines of code.

Here’s an example of how to resolve a merge conflict in Git:

Start by running the git status command to see which files have merge conflicts:

    # Check which files have merge conflicts
    git status

Open the file with the merge conflict in a text editor. You will see that Git has marked the conflicting lines with <<<<<<<, =======, and >>>>>>> markers. The lines between <<<<<<< and ======= represent the changes from the current branch, while the lines between ======= and >>>>>>> represent the changes from the branch being merged.

    <<<<<<< HEAD
    This is the text from the current branch.
    =======
    This is the text from the branch being merged.
    >>>>>>> branch-to-merge

Edit the file to resolve the conflict. You can keep one set of changes, or merge the changes together. Once you have resolved the conflict, remove the <<<<<<<, =======, and >>>>>>> markers from the file.

    This is the text from both branches.

Once you have resolved all the merge conflicts, stage the changes using the git add command:

    # Stage the changes
    git add <filename>

Finally, commit the changes using the git commit command:

    # Commit the changes
    git commit -m "Merge branch-to-merge"

This will commit the changes to the repository and complete the merge.

In summary, resolving merge conflicts in Git requires manually editing the conflicting file to resolve the differences between the two branches. Once the conflicts have been resolved, the changes must be staged and committed to complete the merge.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics