Skip to content
Back to field notes
Field note / 2026··2 min read

Migrate (at least) to Git 2.54

Get Git Hooks natively with Git 2.54

#tech

Since Git 2.54, we can use Git Hooks without any external dependencies!

Git Hooks allow us to trigger actions before or after an event. For example, they allow us to automatically launch a series of tests before pushing our application to a server.

The only downside of using native hooks instead of a library such as Husky is that we can't block a hook if someone does not have at least Git 2.54; which means that if you have to block a commit when the code is not formatted, but one of your colleagues has a version prior to 2.54, the commit will not be blocked. So you need to control that everybody in your team has the right Git version.

But on the other hand, there are many benefits, as some of you may already know: natively handling commit validation, triggering actions before and/or after a push to a server, colocating your hooks next to your other Git-specific configuration, OS-agnostic commands, and so on.

Integrating Git Hooks into your workflow is very simple. Let's imagine that you don't currently have any specific Git config in your codebase.

  1. Get the latest Git version (be careful if you are on a Linux machine, as some repositories have old Git versions).

  2. Create a .gitconfig file (the name does not really matter; you can also call it .gitconfig-local) which will contain your hooks in a TOML format. For example, for a JavaScript project:

[hook "linter"]
  event = pre-commit
  command = npm run lint

[hook "formatter"]
  event = pre-commit
  command = npm run format:check

[hook "pre-commit-validated"]
  event = post-commit
  command = echo "Valid commit ✅"

Here, we use the pre-commit event to launch two scripts to validate our commit: one to lint (analysis of potential bugs) and one to check if the code format is correct, and one post-commit event to display a validation message if the commit is valid.

  1. We need to link this file to your computer and codebase. To do so, we will attach it to the setup of the app. In our current JavaScript example, we are going to use the prepare script keyword to automatically link our Git file in our package.json file.
// package.json
{
  "scripts": {
    "prepare": "git config --local include.path ../.gitconfig"
    ...
  }
}

And then, you just need to launch the setup command of your app to link your codebase to the Git config file! In our example, it will be a simple npm install.

All good now! Your commits will work flawlessly for your whole team! You can even add other Git config-related things to your .gitconfig file.