How-to: Git clean up .orig files generated after conflict resolution

This works even if .orig has been added to .gitignore. Works for any files matching a regular expression.

Preamble

After a merge conflict resolution you’re often left with files ending with .orig extension. I have them added to my global .gitignore. Hence I can’t easily get rid of them with regular: git clean -fd.

Solution

git clean has -e argument for a regular expression to match files. To preview what will happen:
git clean -e '!*.orig' --dry-run

To actually delete the files:
git clean -e '!*.orig' -f

It’s that simple.

Principal Bioinformatics Scientist

My main research interests are data visualization and signal processing for mass spectrometry.