Junior — Middle
How do you resolve and handle conflicts when merging branches in Git?
sobes.tech AI
Answer from AI
When merging branches in Git, conflicts occur when changes in one branch overlap with changes in another. To resolve and fix conflicts, the following steps are usually taken:
- Execute the merge command, for example
git merge branch-name. - If Git reports conflicts, open the files with conflicts — they will contain special markers
<<<<<<<,=======,>>>>>>>. - Analyze the conflicting changes and manually select or combine the necessary parts of the code.
- After resolving conflicts, save the files.
- Add the corrected files to the index using
git add. - Complete the merge with the command
git commit(if it does not happen automatically).
For convenience, visual tools (such as GitKraken, VSCode, or built-in IDE tools) can be used, which help to see and resolve conflicts more clearly.