Lefthook is a fast and flexible Git hooks manager designed to simplify repository automation. It enables running scripts on Git events such as commits, pushes, and merges while keeping configuration centralized in a single YAML file. This tutorial demonstrates how to install Lefthook on Ubuntu 26.04.
Prepare environment
A working Git setup is required before Lefthook installation. Ensure Git is available on the system, as it is used to initialize repositories and trigger hooks. Refer to a post on how to install it.
Install Lefthook
Get the latest available release number from the official repository:
LEFTHOOK_VERSION=$(curl -s "https://api.github.com/repos/evilmartians/lefthook/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Download the appropriate binary:
sudo curl -sSLo /usr/local/bin/lefthook https://github.com/evilmartians/lefthook/releases/latest/download/lefthook_${LEFTHOOK_VERSION}_Linux_x86_64
Grant execution permissions:
sudo chmod a+x /usr/local/bin/lefthook
Confirm installation by checking Lefthook version:
lefthook --version
Testing Lefthook
A simple repository setup can be used to validate hook execution. Create and initialize a sample project:
mkdir myproject && cd myproject && git init
Add a basic Lefthook configuration:
nano lefthook.yml
Example configuration:
pre-commit:
commands:
simple-check:
run: echo 'Hello from Lefthook!'
Activate hooks in the repository:
lefthook install
Create a test commit flow:
touch test.txt
git add .
git commit -m 'test'
Expected output:
Uninstall Lefthook
If Lefthook is no longer needed, run the following command to remove the binary:
sudo rm -rf /usr/local/bin/lefthook
Leave a Comment
Cancel reply