Git merge conflicts using Tortoise Git merge in Windows

2 minute read

Today we wanted to use Tortoise Git Merge, a Windows Git utility which comes with Tortoise Git. It helps us do a 3 way merge and solve our conflicts easily. The advantage of it is that it automatically merges the lines that where uniquely modified in every file and you only need to merge the common changes where the conflicts are. So in our case we had a file , let’s call it README.md, in which we had 1000 changed lines out of which only 2 had a conflict with the file pulled from upstream server. Eclipse and IntelliJ do provide a merge editor but as far as we are concerned they are not automatically merging your unique changes (please correct us if we are wrong). After some searching on the web of how to do so, we found StackOverflow Question 5190188 : Why can’t I use TortoiseMerge as my git merge tool on Windows? which explains different approaches.

So according to the aforementioned question and our experiments, in order to use Tortoise Git Merge you have to download and install Tortoise Git and configure your local .gitconfig file with the following lines:

[core]
	longpaths = true
	autocrlf = true
[merge]
	tool=tortoisemerge
[mergetool "tortoisemerge"]
	cmd = \"C:\\Program Files\\TortoiseGit\\bin\\TortoiseGitMerge.exe\" -base:\"$BASE\" -theirs:\"$LOCAL\" -mine:\"$REMOTE\" -merged:\"$MERGED\"

If you want an one liner equivalent command, you can run the following:

git config --global mergetool.tortoisemerge.cmd "\"C:\\Program Files\\TortoiseGit\\bin\\TortoiseGitMerge.exe\" -base:\"$BASE\" -theirs:\"$LOCAL\" -mine:\"$REMOTE\" -merged:\"$MERGED\""

NOTE: The core section is complimentary for Windows in order to help Git use long paths and overcome Windows 260 character MAX_PATH limitation. Furthermore we need to automatically checkout with file ending using CRLF and push to LF, thus the autocrlf is set to true.

After this short parenthesis, back in action! When you pull from a remote repository, or you merge, or rebase a branch and Git complains about conflicts you can use in your shell or in Git Bash:

git mergetool

Tortoise merge will appear with a display like the following:

Tortoise merge open to merge conflicts

In this image, conflicts are marked with red and the automatically merged lines are marked with yellow. Left side (Theirs) is the version of the file which comes from repository and right side (Mine) is your local version with your changes.

That’s it. We hope this quick guide helped you!

Comments