What methods have you used to resolve conflicts when working with Git?
sobes.tech AI
Answer from AI
When working with Git, conflicts arise when changes in the same section of code are made in different branches. The following methods can be used to resolve them:
-
Manual conflict resolution: Git marks conflicting sections in files with special markers (
<<<<<<<,=======,>>>>>>>). You need to open the file, choose the correct code variant, and delete the markers. -
Using graphical tools: such as GitKraken, SourceTree, or built-in IDE tools (for example, in PhpStorm), which visually display conflicts and make resolution more convenient.
-
The
git mergetoolcommand: launches an external merge tool for easy conflict resolution. -
Rebasing (
git rebase) with conflict resolution along the way: allows applying changes on top of another branch, resolving conflicts as needed.
Example of manual conflict resolution:
<<<<<<< HEAD
console.log("Version from the current branch");
=======
console.log("Version from the branch to merge");
>>>>>>> feature-branch
After choosing the desired option, save the file, then execute:
git add <file>
git commit
This will complete the merge process with the conflict resolved.