Error Codes Wiki

Git Merge Conflict — Resolving File Conflicts During Merge, Rebase, and Cherry-Pick

Warningcommand

Overview

Fix Git merge conflicts when two branches modify the same lines of code, preventing automatic merge and requiring manual conflict resolution.

Key Details

  • Merge conflicts occur when Git cannot automatically combine changes from different branches
  • Conflicts are marked in files with <<<<<<< HEAD, =======, and >>>>>>> branch-name markers
  • Conflicts can happen during merge, rebase, cherry-pick, and stash apply operations
  • Git marks the file as 'both modified' and waits for manual resolution before completing the merge
  • After resolving all conflicts, you must stage the files and complete the merge/rebase

Common Causes

  • Two branches modified the same lines in the same file independently
  • File deleted in one branch but modified in another
  • Rebasing a long-lived branch onto main with many changes in overlapping areas
  • Cherry-picking a commit that depends on context that differs between branches

Steps

  1. 1Identify conflicted files: 'git status' shows files with 'both modified' status
  2. 2Open each conflicted file and look for <<<<<<< markers — choose or combine the changes
  3. 3Remove all conflict markers (<<<, ===, >>>) and save the file with the desired final content
  4. 4Stage resolved files: 'git add resolved-file.txt' for each file
  5. 5Complete the operation: 'git merge --continue' or 'git rebase --continue' depending on the operation

Tags

gitmerge-conflictrebaseresolutionversion-control

More in Command

Frequently Asked Questions

Yes. Run 'git merge --abort' to cancel the merge and return to the state before the merge started. For rebase: 'git rebase --abort'. For cherry-pick: 'git cherry-pick --abort'. No data is lost.