Urgent.News

What's breaking now, across thousands of outlets.

Tech

Git Hooks Not Running for Teammates? Husky vs Lefthook vs pre-commit

Git hooks don't run for teammates because .git/hooks/ is never committed, so every clone starts with no hooks at all. Husky, lefthook, and pre-commit all solve this the same way: the hook definitions live in the repo, and an install step points Git at them. Pick husky if your repo is already a Node project, lefthook if you want one fast binary with no runtime dependency, and pre-commit if your…

Git hooks may not run for teammates because the .git/hooks/ directory is never committed to the repository. This means that every clone starts with no hooks installed. Husky, Lefthook, and pre-commit are tools designed to solve this issue by installing the necessary hook definitions directly in the repository. Choose Husky if your project is already a Node.js project, opt for Lefthook for a single binary with no runtime dependencies, and go with pre-commit if your team primarily uses Python or needs a wide variety of ready-made hooks.

A common problem arises when hooks work on a user's machine but not on a teammate's. This usually happens because the hooks are stored in a hidden directory that is not part of the repository content. To verify whether hooks are installed, run `git config --get core.hooksPath`. If it returns an empty output, no hooks are installed in the clone. If you see output, then hooks are defined in a custom path.

Husky, Lefthook, and pre-commit handle the installation process differently. Husky utilizes the npm prepare script to automatically install hooks during package installation. Lefthook, on the other hand, uses a YAML configuration file to define its hooks, and it can run them in parallel for improved performance. Pre-commit employs a separate configuration file (`.pre-commit-config.yaml`) and uses its own catalog of pre-written hooks, making it a popular choice for Python-heavy teams.

If hooks fail to run after adopting one of these tools, there are a few potential issues to check. First, ensure that the install step ran successfully. For Husky, this is done via the `prepare` script in `package.json`. For Lefthook, check the `lefthook install` command was executed, and for pre-commit, ensure that `pre-commit install` was run.

Another issue may occur when pre-commit is already set in `core.hooksPath`, preventing new hooks from being installed. In such cases, unset the existing path and re-install the hooks.

Local Git GUIs and PATH problems can also interfere with hook execution. For example, a hook that calls `npx` or `node` may fail when using a graphical Git client with a different PATH configuration. The built-in single binary solution of Lefthook helps mitigate this issue, but it still relies on the underlying tools to be present in the PATH.

Lastly, it is essential to remember that hooks should not be the only form of enforcement for code quality. While hooks provide instant feedback, they can be bypassed, and contributors working on forks have never executed the setup steps. Implementing similar checks in a Continuous Integration (CI) pipeline ensures that the merge process enforces the desired standards.

Husky and Lefthook can be configured to run the same commands (e.g., linting, formatting) directly from the CI workflow, ensuring consistency between local and remote environments.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

A $700 Laptop Possessed by Malware: Why I Built Haunted Hardware Exorcist

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine The idea for this project came from the time when my cousin installed a cracked game on some sketchy…

  • Author created Haunted Hardware Exorcist after cousin's malware-infected laptop
  • Device monitors hardware in real-time using algorithms for potential problems
  • Focuses on hardware telemetry and physical load trends to prevent damage

Booo!!! Happy Halloween!

The Scariest Lines of Code I've Ever Written. Boooo!!! Cesar Aguirre Cesar Aguirre Cesar Aguirre Follow Oct 19 The Scariest Lines of Code I've Ever Written. Boooo!!!

GistMyMail: An Open-Weight Gemma Agent for Lazy Morning Email Triage with Zero-Hallucination Proof

This is a submission for the Hacktoberfest Open-Source AI Challenge: Week 3 📬 GistMyMail: The Ultimate Lazy Morning Email Triage Powered by Google Gemma & Deterministic Proof October 20 was…

  • GistMyMail simplifies email triage for developers, freelancers, and students
  • Uses Google Gemma open weights for AI with zero hallucination risk
  • Runs locally, costs nothing in subscriptions or API charges

Verve plans phone tap-to-pay and AI agent payments, CEO says

Verve plans to let customers pay by tapping their phones and, eventually, to let AI assistants make payments on their behalf.

  • Verve CEO Vincent Ogbunude announces phone tap-to-pay and AI agent payments.
  • Plans aim to eliminate payment friction by reducing steps in transactions.
  • Verve has 130 million registered cards, handling 11.2 billion transactions in 2024.

More from Saturday 31 October →