Git
mergetool
.orig files
version control
code collaboration

Git mergetool generates unwanted .orig files

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

When git mergetool leaves *.orig files behind, Git is not corrupting your repository. Those files are backup copies created during merge resolution so you can recover the pre-merge state of a conflicted file if needed. They are useful during conflict resolution, but they are often unwanted once the merge is complete.

Why .orig Files Appear

During merge-tool workflows, Git may create backup files before handing control to the external merge tool. Those backups typically end with .orig.

If a file named app.py is being merged, you may end up with:

text
app.py
app.py.orig

The extra file is not part of your committed merge result unless you add it accidentally. It is just a working-tree artifact.

That distinction matters because many developers first encounter these files during a stressful conflict-resolution session and assume the merge tool has damaged the repository. In reality, the file is usually just a recoverable backup, not a sign that the merge itself is broken.

Disable Backup Retention in Git

If you do not want Git to keep those backups after a successful merge, configure mergetool.keepBackup to false.

bash
git config --global mergetool.keepBackup false

You can also set it only for one repository.

bash
git config mergetool.keepBackup false

With that setting, Git removes the backup files after a merge is resolved successfully.

Confirm the Current Setting

If you are unsure which value is active, inspect it directly.

bash
git config --show-origin --get mergetool.keepBackup

This is useful when a global config, local repo config, or shared team setup may be overriding your expectation.

Clean Up Existing .orig Files Safely

If old .orig files are already scattered through the repository, remove them deliberately rather than by habit. First list them.

bash
find . -name '*.orig' -print

Then delete them if you are sure they are only leftover backups.

bash
find . -name '*.orig' -delete

This is safe only if those files are not meaningful artifacts in your project for some unrelated reason.

Prevent Accidental Staging

Even if you keep backups temporarily, you usually do not want to commit them. Add an ignore rule if your team routinely uses merge tools that generate these files.

gitignore
*.orig

That does not stop creation, but it does stop the files from cluttering git status and from being staged by accident.

Remember the Merge Tool May Also Matter

Git has its own backup behavior, but some third-party merge tools create their own temporary or backup files too. If .orig files still appear after setting mergetool.keepBackup=false, inspect the configuration of the external tool itself.

That distinction matters because disabling Git backup retention will not override separate backup behavior implemented by the tool you launched.

Common Pitfalls

A common mistake is deleting .orig files immediately during an unresolved merge. If the merge is still in progress, those backups may still be useful.

Another is assuming Git committed them automatically. They only become part of history if you stage and commit them.

Developers also sometimes change the Git config but forget that the external merge tool may still create its own backup files.

Summary

  • '*.orig files from git mergetool are backup copies created during merge resolution.'
  • Set mergetool.keepBackup=false to stop Git from keeping them after successful merges.
  • Clean existing .orig files only after confirming they are just leftover backups.
  • Add *.orig to .gitignore if you want to avoid accidental staging.
  • If backups still appear, check the merge tool's own settings as well as Git's.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

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

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.