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-nameAttempts to merge the specified branch into the current branch. If there are conflicts, Git will notify you.
git statusShows the status of the working directory and highlights conflicts.
Manually edit the conflicted files to resolve conflicts.
git add filenameMarks conflicted files as resolved after you have manually edited them.
git commitCompletes the merge process by committing the resolved changes.
git merge --abortCancels 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 mergetoolLaunches a merge resolution tool to help resolve conflicts visually.
git diffDisplays the differences between branches and conflicts.
git commit -m "Resolved merge conflicts"Finalizes the merge after resolving conflicts.