Probably after merge in git you could be faced with an issue about how to resolve unsuccessful merges. In our solution we’ll use gui merge tools, which will help resolve our conflicts by hand.

So, for example, after merging some of the project files could arise with mark CONFLICT :

C:\code\gitara3\g1>git merge upstream/master
Removing lib/templates/haml/scaffold/_form.html.haml
Auto-merging db/schema.rb
CONFLICT (content): Merge conflict in db/schema.rb
CONFLICT (rename/delete): db/migrate/20120826102940_add_optin_to_users.rb deleted in HEAD and renamed in upstream/master. Version upstream/master of db/migrate/20120826102940_add_optin_t
o_users.rb left in tree.
Auto-merging db/migrate/20120826102841_devise_create_users.rb
Removing db/migrate/20120426014546_devise_invitable_add_to_users.rb
Removing config/locales/devise_invitable.en.yml
Removing config/initializers/prelaunch-signup.rb
Removing app/views/users/show.html.haml
Removing app/views/users/index.html.haml
Removing app/views/layouts/application.html.haml
CONFLICT (modify/delete): app/views/layouts/_navigation.html.haml deleted in upstream/master and modified in HEAD. Version HEAD of app/views/layouts/_navigation.html.haml left in tree.
Removing app/views/layouts/_messages.html.haml
Removing app/views/home/index.html.haml
Removing app/views/devise/shared/_links.html.haml
Auto-merging app/views/devise/registrations/new.html.erb
CONFLICT (add/add): Merge conflict in app/views/devise/registrations/new.html.erb
Removing app/views/devise/registrations/edit.html.haml
Auto-merging app/views/devise/registrations/_thankyou.html.erb
CONFLICT (add/add): Merge conflict in app/views/devise/registrations/_thankyou.html.erb
Removing app/views/devise/confirmations/show.html.haml
Auto-merging app/models/user.rb
CONFLICT (content): Merge conflict in app/models/user.rb
Removing app/helpers/users_helper.rb
Removing app/assets/stylesheets/users.css.scss
Auto-merging app/assets/stylesheets/bootstrap_and_overrides.css.scss
Auto-merging app/assets/javascripts/application.js
Auto-merging README.textile
CONFLICT (content): Merge conflict in README.textile
Automatic merge failed; fix conflicts and then commit the result.

It happens when auto-merging tool fails, and after that we need to resolve conflicts by hand. Git have a wrapper for merge tool, which could be called with git mergetool, if you try to run it, git will fail :

C:\code\gitara3\g1>git mergetool
merge tool candidates: tortoisemerge emerge vimdiff
No known merge resolution program available.

To use this wrapper we are going to configure GUI merge tools, we should choose one from several good of them :

All of the approaches listed below based on modifying the .gitconfig file in a user folder (For ex. C:\Users\user). We need to configure .gitconfig by adding additional lines, different for every GUI tool.

Setting up WinMerge with git

    tool = winmerge
[mergetool "winmerge"]
    cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" "$PWD/$LOCAL" "$PWD/$REMOTE" "$PWD/$MERGED"
        trustExitCode = false
    keepBackup = false
    tool = winmerge
[difftool "winmerge"]
    cmd = \"C:\\Program Files\\WinMerge\\WinMergeU.exe\" "$PWD/$LOCAL" "$PWD/$REMOTE" "$PWD/$MERGED"
        trustExitCode = false
    keepBackup = false

Setting up KDiff3 with git

        tool = kdiff3
[mergetool "kdiff3"]
        path = c:/Program Files/KDiff3/kdiff3.exe
        tool = kdiff3
        guitool = kdiff3
[difftool "kdiff3"]
        path = c:/Program Files/KDiff3/kdiff3.exe

Setting up TortoiseMerge with git

    tool = tortoise
[mergetool "tortoise"]
    cmd = \""c:/Program Files/TortoiseSVN/bin/TortoiseMerge.exe"\" -base:"$BASE" -theirs:"$REMOTE" -mine:"$LOCAL" -merged:"$MERGED"

Using git mergetool and git difftool

After successful modification of .gitignore we are able to use merge tools in a console, for example :

C:\code\gitara3\g1>git mergetool
Normal merge conflict for 'README.textile':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (tortoise):
Normal merge conflict for 'app/models/user.rb':