Git
Git diff
Patience algorithm
Code versioning
Software development

How to set patience as default git diff algorithm

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

Introduction

Git lets you choose different diff algorithms, and patience is often preferred for readability when code has been moved around or lightly refactored. If you want Git to use it by default, the configuration is simple: set diff.algorithm to patience.

Set It Globally

To make patience diff the default for all repositories for your user account:

bash
git config --global diff.algorithm patience

Check the result:

bash
git config --global --get diff.algorithm

That should print:

text
patience

Set It Only for One Repository

If you want the change only in the current repository:

bash
git config diff.algorithm patience

This writes the setting into that repository's .git/config instead of your global Git config.

What Patience Diff Changes

Git's default diff algorithm is usually Myers. Patience diff tries to align unique lines first, which often produces cleaner hunks when blocks were rearranged rather than rewritten from scratch.

It is especially helpful when:

  • functions were reordered
  • small edits were made inside moved code
  • the default diff looks noisy or misleading

It is not automatically better for every file, but many developers prefer it for source code review.

Use It Per Command When Needed

Even if you do not want it as a permanent default, you can request it for one command.

bash
git diff --diff-algorithm=patience

You can also use it with other Git commands that produce diffs, such as git show.

bash
git show --diff-algorithm=patience HEAD~1

This is useful if you only want patience for specific reviews.

Compare It With the Default

A practical way to decide whether you want it globally is to compare outputs on a file with moved code.

bash
git diff --diff-algorithm=myers
git diff --diff-algorithm=patience

If the patience version consistently matches your mental model of the change better, making it the default is reasonable.

Config Scope Matters

Git configuration can exist at multiple scopes:

  • system
  • global
  • local repository

If you set the option globally and still do not see the expected behavior, check whether a repository-local config overrides it.

bash
git config --show-origin --get diff.algorithm

That command shows where the active value came from.

Git also supports other algorithms such as minimal and histogram.

For some codebases, histogram can be a strong alternative. The right choice is about readability, not ideology.

Still, if the specific goal is "make patience the default," diff.algorithm patience is the correct configuration.

When You Might Prefer a One-Off Flag Instead

Even if patience is your favorite default, there are cases where you may still want another algorithm for a specific review. Large generated files, heavily repetitive content, or unusual refactors can sometimes look better with histogram or myers.

That is one reason the per-command flag remains useful even after setting a global default. The configuration changes the baseline, but Git still lets you override it on demand.

Common Pitfalls

A common mistake is setting the option in one repository and then expecting it to affect all repositories. Local config stays local.

Another mistake is confusing a diff algorithm with whitespace handling or rename detection. Those are separate settings.

Developers also sometimes expect hosted Git platforms to honor their local diff algorithm preference. Local Git config affects your local Git commands, not how every web UI renders diffs.

Summary

  • Set patience globally with git config --global diff.algorithm patience.
  • Set it per repository with git config diff.algorithm patience.
  • Use --diff-algorithm=patience for one-off commands.
  • Patience diff is often easier to read when code is moved or lightly reorganized.
  • Use git config --show-origin --get diff.algorithm if you need to debug where the setting comes from.

Related reading
Course
Intermediate
27 lessons
15 hours
DSA Fundamentals

Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Data Structures & Algorithms practice on Codemia

Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.

Practice algorithms

All Rights Reserved.