Git Pre-Commit Hook Can Auto-Optimize Images Locally Before Every Commit
Uncompressed images committed to Git repositories permanently inflate repo size, since Git retains all historical blobs even after files are later shrunk. A pre-commit hook using locally installed tools pngquant and jpegoptim can automatically compress staged PNG and JPEG files before they enter a commit, with no third-party uploads required. The script re-stages optimized files automatically and skips compression if it would make a file larger, ensuring no unintended changes occur. As an added privacy benefit, stripping EXIF metadata removes embedded GPS coordinates that could otherwise expose sensitive location data in public repositories. For team-wide enforcement, the pre-commit framework allows the configuration to be version-controlled, ensuring all contributors and CI pipelines apply the same image optimization rules.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in