Git Mergetool – Merging With a GUI

Commands discussed in this section:

Merging With a GUI

Git can also work with a large number of GUI tools for helping with merging. A couple of popular GUI tools used on Linux are kdiff3 and meld. They are worth trying (you may need to install them if they aren’t installed yet).

Back To The Same Old Conflict

We’ll go back to the conflict in the the second line of the README file, from our repository as described in the Merging Branches With a Conflict page.

Merging with kdiff3

If you want to try out kdiff3 you could type:

$ git mergetool -t kdiff3Merging the files: READMENormal merge conflict for 'README': {local}: modified {remote}: modifiedHit return to start merge resolution tool (kdiff3):

You can see 3 windows at the top and a large window on the bottom in the kdiff3 GUI. The 3 windows on the top, from left to right are:

  • The common ancestor version
  • The current branch (master)
  • The other branch (test)

The large window on the bottom is editable and is where the result of the merge is placed. kdiff3 makes merging easy. You can put your mouse over the Merge Conflict text and press the right mouse button, which will let you choose which version of text you want:

You can then choose what you would like for the merge. For example, if you chose Select Line(s) from B, the window at the bottom with the merge result is changed to this:

When you are satisifed with the merged version of README, you can click on File–>Save and exit and then resolve the conflict by adding README to the index.

Merging with meld

If you want to try to use meld you can type:

$ git mergetool -t meldMerging the files: READMENormal merge conflict for 'README': {local}: modified {remote}: modifiedHit return to start merge resolution tool (meld):

You would then see:

With meld, three windows are shown, and left to right are:

    • The local branch (master branch)
    • The current version that you are merging into

The other (or “remote”) version (from the test branch)

To choose the text from the master branch, click on the black arrow in the left-most window at the top right. The resulting merge looks like this:

Clicking on a black arrow moves text to other file (meld copies the text to the other file, and removes the text from where it was). After you have saved the version of README, you can resolve the conflict in git.

Configure Git For Your Mergetool Of Choice

To configure git to remember which merge tool you want, type git config –global merge.tool [tool]. For example, if you want git mergetool to automatically use kdiff3 as our mergetool, we would type:

$ git config --global merge.tool kdiff3

There are many merge tools available and everybody has their own favorites.

Next: Remote repositories
Previous: Merging With a Conflict

Merging Branches Without a Conflict

Recent Articles

Where Do I Get Git?

Where do you get git? We have the answer to that for Linux (Ubuntu, Debian, and Red Hat), Windows, and Apple OS as well as over 30 free git tutorials.

What is the deal with the Git Index? What is the Git Index?

The git "index" is where you place files you want committed to the git repository. Learn more about the git index and git commit by selecting this link.

What Every VCS Must do

Version Control System ("VCS") need to be able to provide to its users? GitGuys explains exactly what it needs to include and provides tutorials on Git.

Visualising Branches And Their Commits

We explain and discuss the use of the git show-branch, gitg, gitk and qgit in this Tutorial. Complete with examples.

“Tracking Branches” And “Remote-Tracking Branches”

Both Tracking Branches and Remote Tracking Branches are created on the git client when a git clone command is used.

Related Stories

Leave A Reply

Please enter your comment!
Please enter your name here

Stay on op - Ge the daily news in your inbox