How to Set Diff Tool in Git: Simple Guide
To set a diff tool in Git, use the command
git config --global diff.tool <toolname> to specify your preferred diff tool. Then run git difftool to use it for comparing changes.Syntax
The basic syntax to set a diff tool in Git is:
git config --global diff.tool <toolname>: Sets the diff tool globally for all repositories.git difftool: Runs the configured diff tool to compare changes.- You can also set a custom command with
git config --global difftool.<toolname>.cmd <command>.
bash
git config --global diff.tool <toolname> git difftool
Example
This example sets meld as the diff tool and then runs it to compare changes in the current Git repository.
bash
git config --global diff.tool meld git difftool
Output
Launching meld to compare files...
Common Pitfalls
Common mistakes include:
- Not installing the diff tool before setting it in Git.
- Forgetting to use
--globalif you want the setting to apply to all repositories. - Using an incorrect tool name that Git does not recognize.
- Not running
git difftoolafter setting the tool, expectinggit diffto use it automatically.
bash
Wrong: git config diff.tool meld # Missing --global, applies only to current repo Right: git config --global diff.tool meld
Quick Reference
| Command | Description |
|---|---|
| git config --global diff.tool | Set diff tool globally |
| git difftool | Run the configured diff tool to compare changes |
| git config --global difftool. | Set custom command for diff tool |
| git config --global difftool.prompt false | Disable prompt before launching diff tool |
Key Takeaways
Use
git config --global diff.tool <toolname> to set your preferred diff tool.Run
git difftool to launch the configured diff tool for comparing changes.Make sure the diff tool is installed on your system before configuring it in Git.
Use the
--global flag to apply the setting to all repositories.You can customize the diff tool command if needed with
difftool.<toolname>.cmd.