~/
hackweb.dev
Resolving Merge Conflicts
Quiz
⌘K
...
~/
/tutorials
/git/git-merge-conflicts/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
Comment
0 / 300
Typo
Grammar
Broken link
Clarify
Code
en/tutorials/git/9git-merge-conflicts
Write
Preview
Diff
# Resolving Merge Conflicts Conflicts happen when Git can't automatically combine changes from two branches. You must resolve them manually. ## When Conflicts Occur - Two branches modify the same line in a file - One branch deletes a file the other modifies - Both branches add a file with the same name ## Conflict Markers ```text <<<<<<< HEAD your changes on the current branch ======= changes from the incoming branch >>>>>>> feature ``` - `<<<<<<< HEAD` — your current changes - `=======` — divider - `>>>>>>> feature` — incoming changes ## How to Resolve 1. Open the conflicted file 2. Choose which changes to keep (or combine both) 3. Delete the conflict markers 4. Save the file ```bash git add resolved-file.js git commit -m "Resolve merge conflict in resolved-file.js" ``` ## Using a Merge Tool ```bash git mergetool ``` Opens a visual diff tool to help resolve conflicts side by side. ## Aborting a Merge ```bash git merge --abort ``` Returns to the state before the merge started. ## Best Practices - Resolve conflicts soon after they appear - Communicate with your team about conflicting changes - Test your code after resolving conflicts - Use `git diff` to review changes before committing ## Common Mistakes - Accidentally deleting code from the other branch - Forgetting to remove conflict markers - Committing without `git add` first - Not testing after resolution
No changes yet
Reset to original
Submit suggestion
cancel