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
- 1Identify conflicted files: 'git status' shows files with 'both modified' status
- 2Open each conflicted file and look for <<<<<<< markers — choose or combine the changes
- 3Remove all conflict markers (<<<, ===, >>>) and save the file with the desired final content
- 4Stage resolved files: 'git add resolved-file.txt' for each file
- 5Complete the operation: 'git merge --continue' or 'git rebase --continue' depending on the operation
Tags
gitmerge-conflictrebaseresolutionversion-control
More in Command
linux-exit-code-127Linux Exit Code 127 — Command Not Found
Warninglinux-exit-code-126Linux Exit Code 126 — Permission Denied
Warninglinux-segmentation-faultLinux Segmentation Fault (Signal 11)
Errorlinux-killed-signal-9Linux Process Killed (Signal 9)
Errorlinux-ansible-playbook-errorsAnsible Playbook Errors — Task Failures, SSH Connectivity, and Variable Resolution Issues
Warninglinux-terraform-errorsTerraform Errors — Plan, Apply, and State Management Failures
WarningFrequently 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.