• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

“git mergetool” Command Examples

by admin

The git mergetool command is a useful tool in Git that helps you resolve merge conflicts that occur during the merging process. When Git encounters conflicting changes between branches during a merge, it can’t automatically resolve the conflicts. In such cases, the git mergetool command comes into play.

Here’s how you can use the git mergetool command:

  • Start by executing the git merge command, which triggers a merge and identifies conflicting changes between branches.
  • When Git encounters conflicts, it pauses the merge process and provides information about the conflicted files.
  • To resolve these conflicts, you can run the git mergetool command.

When you run git mergetool, Git opens an external merge tool that helps you visualize and resolve conflicts within the affected files. The specific merge tool opened depends on your Git configuration and the tools available on your system.

The merge tool presents you with a side-by-side view of the conflicting changes, typically with the base version (common ancestor), the current branch version, and the version from the branch being merged. The tool provides options for accepting or rejecting changes from either side, or manually editing the file to craft a custom resolution.

Once you’ve resolved the conflicts using the merge tool, save the changes and close the tool. Git will detect that the conflicts have been resolved for that particular file.

After resolving all conflicts in all affected files, you can finalize the merge by executing the git commit command. This creates a new merge commit that records the resolution of conflicts and completes the merge operation.

It’s worth noting that the specific merge tool you use can be configured in your Git configuration. By default, Git tries to use common merge tools such as vimdiff, meld, kdiff3, or opendiff, depending on your operating system and available tools. You can customize the merge tool configuration by modifying the Git configuration file.

git mergetool Command Examples

1. Launch the default merge tool to resolve conflicts:

# git mergetool

2. List valid merge tools:

# git mergetool --tool-help

3. Launch the merge tool identified by a name:

# git mergetool --tool tool_name

4. Don’t prompt before each invocation of the merge tool:

# git mergetool --no-prompt

5. Explicitly use the GUI merge tool (see the merge.guitool config variable):

# git mergetool --gui

6. Explicitly use the regular merge tool (see the merge.tool config variable):

# git mergetool --no-gui

Filed Under: Linux

Some more articles you might also be interested in …

  1. kubetail Command Examples
  2. What is the purpose of .bashrc file in Linux
  3. lxi Command Examples in Linux
  4. argon2: Calculate Argon2 cryptographic hashes (Command Examples)
  5. partprobe Command Examples in Linux
  6. “Abort command issued nexus” error messages in /var/log/messages file
  7. nslookup: command not found
  8. “gnmic set” Command Examples
  9. telinit Command Examples in Linux
  10. g++: Compiles C++ source files

You May Also Like

Primary Sidebar

Recent Posts

  • Vanilla OS 2 Released: A New Era for Linux Enthusiasts
  • mk Command Examples
  • mixxx Command Examples
  • mix Command Examples

© 2025 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright