Can anybody please explain what is the best to resolve conflicts in Git. I am currently using Tortoise Git as well as SourceTree. With TortoiseGit, after getting a conflict, we get the option to "resolve conflict using theirs" or "resolve conflict using mine" in both ways it is not working. What is the best practice?
2 Answers
In most cases, neither of these options is what you want. In most cases, you'll need to go to each conflicting code and manually merge the changes. git marks these conflicting code which you can look for then easily.
Automatic conflict resolution with theirs and mine only work for very limited situations.

- 62,238
- 13
- 100
- 144
-
To add to this, look through the code for `<<<<<<<`, `=======`, and `>>>>>>>`. These sections will mark conflicted sections of code. Manually resolve each of these sections, `add` and `commit`. See [Pro Git](http://git-scm.com/book/en/Git-Branching-Basic-Branching-and-Merging#Basic-Merge-Conflicts) for details. – ChrisGPT was on strike Dec 24 '13 at 13:09
-
1git diff, git status, and most git GUI should also show the files and/or parts marked for merging. – Lie Ryan Dec 24 '13 at 13:26
Resolving conflicts manually, by editing the file to remove the <<<<<<< HEAD
, =======
,
and >>>>>>>
markers is one way but I would not consider it the best way.
- Maybe your IDE already has something built in.
- For example, IntelliJ has conflict resolution capability which can be run in the IDE or also from command line. See this also.
Recommend using a free GUI such as:
- Meld
- kdiff3
- SourceGear DiffMerge
- P4Merge
- Free, but when you run the installer, disable all of the options except the "Visual Merge Tool" otherwise it will prompt to connect to a Perforce server.
- TortoiseMerge which is part of TortoiseSVN
- WinMerge
- If you use Visual Studio there is vsDiffMerge.exe that comes with it.
To set a default mergetool in git, set the following global
git config variables, where "toolname"
is the merge tool you have installed:
git config --global merge.tool "toolname"
git config --global mergetool.toolname.path "\path\to\toolname"
Refer also to:
https://developer.atlassian.com/blog/2015/12/tips-tools-to-solve-git-conflicts/
What's the best visual merge tool for Git?
What's a good (free) visual merge tool for Git? (on windows)

- 2,956
- 1
- 27
- 46