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.
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:
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.
You can also set it only for one repository.
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.
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.
Then delete them if you are sure they are only leftover backups.
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.
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
- '
*.origfiles fromgit mergetoolare backup copies created during merge resolution.' - Set
mergetool.keepBackup=falseto stop Git from keeping them after successful merges. - Clean existing
.origfiles only after confirming they are just leftover backups. - Add
*.origto.gitignoreif you want to avoid accidental staging. - If backups still appear, check the merge tool's own settings as well as Git's.
Related reading
- git mergetool reports No files need merging
- git mv and only change case of directory
- Git name and email address configuration
- Git Needed a single revision error
- Git number of commits per author on all branches
- Git on Windows How do you set up a mergetool?
- git partial merge, not whole branch
- Git please tell me who you are error
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.