Today I learned that I can set up my own filters for doing substitutions on commit/checkout with Git.

Why is that useful?

GitHub restricts files to 100 MB. What if you want to push a file to your GitHub repository that’s bigger than 100 MB?

You can use Clean and Smudge to compress your file.

git-scm.com clean git-scm.com smudge images are from https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes

Clean and Smudge

  1. Decide which file types you want to compress and add them to .gitattributes

For example, for .csv files, add the following line to a file .gitattributes in your Git repository.

*.csv compress

Here, compress is the name of the filter you have to set up. But you can name it however you like.

  1. Write your compress filter

In the terminal inside the root folder of your Git project, add the following commands:

git config filter.compress.clean gzip
git config filter.compress.smudge gzip -d

The name of the git filter is compress. It uses gzip to compress the files on clean (before files are staged), and de-compress them on smudge (before files are checked out).

Further Reading