Git Commands for Handling Merge Conflicts
Posted on June 7, 2024 • 1 min read • 193 wordsLearn how to efficiently handle merge conflicts in Git with these essential commands and techniques.
Merge conflicts can be challenging, but Git provides commands to handle them efficiently. Here’s how to manage merge conflicts:
git merge branch-name
Attempts to merge the specified branch into the current branch. If there are conflicts, Git will notify you.
git status
Shows the status of the working directory and highlights conflicts.
Manually edit the conflicted files to resolve conflicts.
git add filename
Marks conflicted files as resolved after you have manually edited them.
git commit
Completes the merge process by committing the resolved changes.
git merge --abort
Cancels the merge process and reverts to the previous state.
Conflict markers in files look like:
<<<<<<< HEAD
Your changes
=======
Changes from branch
>>>>>>> branch-name
Edit these sections to resolve conflicts, choosing which changes to keep.
git mergetool
Launches a merge resolution tool to help resolve conflicts visually.
git diff
Displays the differences between branches and conflicts.
git commit -m "Resolved merge conflicts"
Finalizes the merge after resolving conflicts.