Sometimes when you merge two git branches, it might give you conflict. Conflict occurs because the same line in the same file has been edited differently in the two branches. This confuses git as to which change to accept and merge. Git conflicts are to be always resolved manually before git can proceed with the merge.
For example, I have two different branches here named current-branch and dev-branch. I want to merge the changes in dev-branch to current-branch now but I am getting a conflict.
Now, to resolve the conflict, you the git mergetool
If you have not already configured the tool, you will need to configure it using any of the text editor software available in your machine as follows.
The above command shows the options and you can choose which editor to set as the default as follows
The above command will open the mergetool in vimdiff editor and will show the changes to the file in both branches. HEAD refers to the current branch and the second line refers to the new-branch
Now all you need to do, is just remove the HEAD and new-branch line and decide what change to go among the two lines in different branch and save the file. Once done add the file to git again and commit it and merge should go fine.
Leave a reply