Skip to article frontmatterSkip to article content

Automatically update pre-commit hook versions

I figured out a way to automatically update all of the git pre-commit hook versions at once!

pre-commit is a useful command line tool for running simple commands before every git commit. I use it to enforce things like flake8 and black in many of my projects.

However, I find it really annoying to keep manually updating my pre-commit hooks with new versions, particularly because pre-commit doesn’t let you specify wild-cards.

Fortunately, I recently came across the pre-commit autoupdate documentation. This lets you automatically update to the latest released versions of all-precommit hooks. Simply run:

pre-commit autoupdate

And it will update your .pre-commit-config.yaml file with the latest versions. This feels like the easiest way to keep these configurations updated, at least until GitHub adds dependabot support for pre-commit.

Automate the above with pre-commit.ci

Update: A few folks mentioned that you can actually automate this whole process by using pre-commit.ci, a service for using pre-commit’s functionality with automated jobs.

That service will both automatically run pre-commit on your Pull Requests, and will also update your pre-commit dependencies on the fly.