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

Related:

Merging Branches Without a Conflict