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.
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:
Check the result:
That should print:
Set It Only for One Repository
If you want the change only in the current repository:
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.
You can also use it with other Git commands that produce diffs, such as git show.
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.
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.
That command shows where the active value came from.
Related Algorithms
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=patiencefor one-off commands. - Patience diff is often easier to read when code is moved or lightly reorganized.
- Use
git config --show-origin --get diff.algorithmif you need to debug where the setting comes from.
Related reading
- How to solve my difficulty making algorithms?
- How to solve the following graph game
- How to solve Tic Tac Toe 4x4 game using Minimax Algorithm and Alpha Beta Pruning
- How to solve Tn Tn/2 Tn/4 Tn/8 n
- How to set specific Java version to Maven?
- How to show full-file Git blame in Visual Studio Code
- How to solve Tn Tn - 1 n
- How to sort a collection by date in MongoDB?

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 courseTrack 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.