Git Smudge and Clean Filters

The Smudge & Clean

The Smudge is the equivalent to “Run this code whenever you check anything out”.

The Clean is the equivalent to “Run this code whenever you check anything in”.

The Smudge and Clean are most commonly used for things like credentials (in connection strings or keys for AWS etc).

The Usage in Git

Git provides filters which you can access via your attributes and config files.

Filters are arbitrary Unix software.  They must conform to the standard interface for all Unix software:  take input via stdin write output to stdout , exit with a 0 for success or any number up to 255 for failure, etc.  Unfortunately, git seems to suppress filter output whether it happens on stdout or stderr .

However, “Arbitrary Unix software” means you can implement these filters in a huge range of ways.  you could easily use Node.js, Ruby and Perl.

Perl Example

I’ve provided an example repository called “smudge-clean” that registers the Clean and Smudge filters by running the “” file.  There are test configs in the “TestConfigs” folder which shows the filters working for both “appSettings” and “connectionStrings”.

One thought on “Git Smudge and Clean Filters

  • Wow! Simply outstanding! Thanks a lot for the info discussed! I know you have placed a lot of initiative right into this and I wanted to inform you exactly how grateful I am! There need to be more blog sites similar to this on the net! I will certainly bookmark and subscribe to your exceptional web site! Hope you produced much more amazing things in the near future and I will return and also read it! Maintain the great work!

Leave a Reply