Modern native Git hooks made easy 🐶 woof!

Overview

husky

Open Collective

Modern native Git hooks made easy

Husky improves your commits and more 🐶 woof!

Install

npm install husky -D

Usage

Edit package.json > prepare script and run it once:

npm set-script prepare "husky install" && npm run prepare

Add a hook:

npx husky add .husky/pre-commit "npm test"

Make a commit:

$ git commit -m "Keep calm and commit"

For more use cases, see documentation.

Documentation

https://typicode.github.io/husky

Important Upgrading from v4 to v6 requires additional steps, please see the docs.

Articles

License

MIT

Companies

Become a sponsor and have your logo here and in the docs

The full list of Sponsors can be viewed in the docs, on Open Collective and on GitHub sponsors.

Comments
  • Hooks not working

    Hooks not working

    I have set up husky commit hooks to run on commit and push, it works for me and another dev, but for one dev the commit hooks do not get run. Not sure what the issue is here

    opened by standayweb 91
  • Husky + GitKraken = 💥

    Husky + GitKraken = 💥

    So after adding Husky to my local project, all my local commits are now taking an eternity when using GitKraken. Note, I believe this issue is specific to GitKraken, so it's unlikely that it's a Husky issue per-se, but it might be nice if the two teams had an issue in which to discuss getting it fixed?

    I've spoken to the GitKraken team and given them as much information as possible (including giving them a link to this issue). But perhaps some of the Husky team might be able to give some pointers as to where to start looking for the cause?

    opened by Siyfion 80
  • Command

    Command "husky-run" not found.

    Just have upgraded from v4.3.8 to v5.0.9 and got the error

    have tried to uninstall/install husky, remove npde_modules - nothing helped

    > git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
    error Command "husky-run" not found.
    
    opened by budarin 66
  • 'husky install' fails if '.git' directory does not exists

    'husky install' fails if '.git' directory does not exists

    I have a postinstall script in a NPM package:

    "postinstall": "is-ci || husky install",
    

    If I download the repository using Github UI (Code -> Download ZIP), after extracting it, executing npm install raises Error: .git can't be found:

    postinstall error
    > [email protected] postinstall /.../simple-icons-font-develop
    > is-ci || husky install
    
    /.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20
            throw new Error(".git can't be found");
            ^
    
    Error: .git can't be found
        at Object.install (/.../simple-icons-font-develop/node_modules/husky/lib/commands/install.js:20:15)
        at Object.<anonymous> (/.../simple-icons-font-develop/node_modules/husky/lib/bin.js:43:19)
    

    I can prevent the error doing something like this:

    "postinstall": "node -e \"if(require('fs').existsSync('.git')){process.exit(1)}\" || is-ci || husky install",
    

    But it seems a bit hacky. What would be the recommended way to solve this?

    opened by mondeja 49
  • Husky hooks skipped

    Husky hooks skipped

    OS: MacOS 10.15.2 (19C57) Git: git version 2.24.1

    ❯ which git /usr/local/bin/git

    ❯ node -v v13.5.0

    ❯ which node /usr/local/bin/node

    ❯ which npx /usr/local/bin/npx

    Node.js installed with brew package manager

        "husky": "^4.0.6",
    

    When making commit in VSCode GUI

    Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
    Skipping pre-commit hook
    Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
    Skipping prepare-commit-msg hook
    Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
    Skipping commit-msg hook
    Can't find npx in PATH: /usr/local/Cellar/git/2.24.1/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin
    Skipping post-commit hook
    

    Everything works fine when making commit from VSCode terminal.


    Version 3 works fine. Sample output from v3:

    Info: can't find node in PATH, trying to find a node binary on your system
    husky > pre-commit (node v13.5.0)
    Stashing changes... [started]
    Stashing changes... [skipped]
    → No partially staged files found...
    Running tasks... [started]
    Running tasks for *.{js,ts,tsx,css,md} [started]
    tslint --fix [started]
    tslint --fix [completed]
    prettier --write [started]
    prettier --write [completed]
    git add [started]
    git add [completed]
    Running tasks for *.{js,ts,tsx,css,md} [completed]
    Running tasks... [completed]
    
    opened by Alex0007 46
  • Bug commit from vscode

    Bug commit from vscode

    After upgrade to husky v5, git commit from vscode always fail (via terminal is ok).

    image

    > git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
    .husky/pre-commit: line 4: npx: command not found
    husky - pre-commit hook exited with code 127 (error)
    

    npm version: 7.5.1 node version: 15.8.0

    Hooks

    // pre-commit
    #!/bin/sh
    . "$(dirname "$0")/_/husky.sh"
    
    npx lint-staged
    
    opened by RigottiG 45
  • [4.0.0 | Git Bash | Windows 10] stdin is not a tty

    [4.0.0 | Git Bash | Windows 10] stdin is not a tty

    Husky 4.0.0 isn't working in Git Bash for Windows 10, triggering a stdin is not a tty error for every git operation that triggers a hook.

    Versions

    OS: Windows 10 1903 Shell: Git Bash (GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)) Git: git 2.24.1.windows.2

    HUSKY_DEBUG=1 npm install husky --save-dev

    $ HUSKY_DEBUG=1 npm install husky --save-dev
    
    > [email protected] install C:\dev\test\husky4-tty-test\node_modules\husky
    > node husky install
    
    husky > Setting up git hooks
    husky:debug Current working directory is C:\dev\test\husky4-tty-test\node_modules\husky
    husky:debug INIT_CWD is set to C:\dev\test\husky4-tty-test
    husky:debug Git rev-parse command returned:
    husky:debug   --git-common-dir: undefined
    husky:debug   --show-prefix:
    The "path" argument must be of type string. Received type undefined
    husky:debug TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
        at validateString (internal/validators.js:112:11)
        at Object.resolve (path.js:139:9)
        at getDirs (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:27:49)
        at run (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:62:62)
        at Object.<anonymous> (C:\dev\test\husky4-tty-test\node_modules\husky\lib\installer\bin.js:85:1)
        at Module._compile (internal/modules/cjs/loader.js:959:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
        at Module.load (internal/modules/cjs/loader.js:815:32)
        at Function.Module._load (internal/modules/cjs/loader.js:727:14)
        at Module.require (internal/modules/cjs/loader.js:852:19)
    husky > Failed to install
    
    > [email protected] postinstall C:\dev\test\husky4-tty-test\node_modules\husky
    > opencollective-postinstall || exit 0
    
    Thank you for using husky!
    If you rely on this package, please consider supporting our open collective:
    > https://opencollective.com/husky/donate
    
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN [email protected] No description
    npm WARN [email protected] No repository field.
    
    + [email protected]
    added 48 packages from 22 contributors and audited 48 packages in 2.047s
    
    3 packages are looking for funding
      run `npm fund` for details
    
    found 0 vulnerabilities
    

    HUSKY_DEBUG=1 git commit

    Note: on the fresh test repo, this command worked because the first command failed so the hooks did not install properly. On an existing repo with existing hooks, it looks like this:

    husky:debug husky v4.0.0 (created at 1/7/2020, 1:24:18 PM)
    husky:debug pre-commit hook started
    husky:debug Current working directory is /c/dev/test/existing-repo
    husky:debug pre-commit hook started
    stdin is not a tty
    husky:debug yarn husky-run exited with 1 exit code
    
    bug 
    opened by wKovacs64 42
  • Git LFS and husky prepush hook?

    Git LFS and husky prepush hook?

    I just tried to husky a prepush script and nothing happened. Looking at .git/hooks/pre-push I see that I already have a hook there:

    #!/bin/sh
    command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
    git lfs pre-push "$@"
    

    Running node node_modules/husky/bin/install.js doesn't help:

    husky
    setting up hooks
    skipping pre-push hook (existing user hook)
    done
    

    I guess that's good, as I don't want Git LFS to break and get some large files in the repo without noticing...

    Is there a husky solution for having a prepush while also using git-lfs?

    opened by orlin 41
  • husky with sourcetree : Can't find node in PATH, trying to find a node binary on your system

    husky with sourcetree : Can't find node in PATH, trying to find a node binary on your system

    I'm trying to use husky precommit with sourcetree. The precommit command is run but i get the following error:

    image

    Does anybody know what's wrong? I'm using n.

    OS: macOS Mojave 10.14 Node: 10.13 $ which node: /usr/local/bin/node npm: 6.4.1 $ whick npm: /usr/local/bin/npm

    image

    opened by zhaozhe0831 40
  • Does not install git hooks when using yarn

    Does not install git hooks when using yarn

    When running yarn add husky --dev, the git hooks do not get set up. I have to run the install script manually, and then it works fine.

    Yarn version: 0.17.9

    opened by Jflinchum 40
  • Husky setting wrong folder in monorepo (lerna/yarn workspace)

    Husky setting wrong folder in monorepo (lerna/yarn workspace)

    Today I've noticed that Husky hooks suddenly stopped working in a monorepo. After investigating I've found out that file husky.local.sh inside .git\hooks had an entry on last line cd "packages/shared/". After removing this line Husky hooks started to work again.

    My folder structure is like: root: -package.json (with Husky hooks setup) -.git --packages ---shared -----package.json ---web ------package.json

    Could this happen when I ran yarn add/install or lerna clean && lerna bootstrap from a sub-directory? Is Husky aware of lerna/yarn workspaces? One solution to always use the right directory would be to check package.json for husky key.

    OS: Windows 10 Terminal: webstorm, CMD, cygwin Since issue was pinpointed I'm not including command's outputs.

    wontfix 
    opened by tad3j 34
  • Permission issue with pnpm node-linker=hosited

    Permission issue with pnpm node-linker=hosited

    Troubleshoot

    • [x] Before creating an issue, please check:

    Context

    Github action log:

      . postinstall$ husky install
      . postinstall: sh: 1: husky: Permission denied
      . postinstall: Failed
    

    Everything works fine in my project at vuepress-theme-hope untill I add node-linker=hosited to .npmrc for testing (I am using pnpm)

    Since other packages which has postinstall (like esbuild) are not metting permission issues, I think that the fix may need to be applied here.

    I did not look in through husky code yet, and I am not sure if the maintainer would like to check this first. I would be happy if you want more information, Thank you!

    opened by Mister-Hope 3
  • Shellcheck complains about hook script

    Shellcheck complains about hook script

    Troubleshoot

    • [x] Before creating an issue, please check: https://typicode.github.io/husky/#/?id=troubleshoot

    Context (This is a minor issue: Functionality isn't affected.)

    Scripts generated by husky add contain the line:

    . "$(dirname -- "$0")/_/husky.sh"
    

    Shellcheck, the popular shell script linter, doesn't care for that line. It complains:

    Not following: ./_/husky.sh was not specified as input (see shellcheck -x). shellcheck(SC1091)
    

    The rule in question, SC1091, is complaining about Shellcheck not being able to access the referenced file. I can't think of a way to satisfy the rule, so it may be that the best solution is to have husky add emit a shellcheck disable directive above it:

    # shellcheck disable=SC1091
    . "$(dirname -- "$0")/_/husky.sh"
    

    Of course, another solution would be for developers to simply ignore the warning, but I believe it's very common for devs who use VS Code to have the Shellcheck extension installed (it has 500,000+ downloads) and enabled by default, so an extra line to silence the warning might avoid some confusion. Or maybe there's a more Shellcheck-friendly way to run husky.sh.

    opened by TrevorBurnham 0
  • update docs to add message about restarting vs code

    update docs to add message about restarting vs code

    VS Code can get into a weird state where husky pre-commits will fail with command not found but the solution is to simply restart VS Code. see https://stackoverflow.com/a/73635509/5504797

    opened by claycoleman 0
  • Adjust instructions for nvm workaround

    Adjust instructions for nvm workaround

    I scoured a lot of GitHub issues and Stack Overflow problems. The difficulty in just using:

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    

    is that - by default - nvm.sh will run the default Node version which isn't necessarily the project's node version. This still won't save anybody manually bouncing between Node versions within different projects, but .nvmrc is a very common practice and this should assuage people who run Husky in a project using an .nvmrc file that differs from their NVM default.

    opened by kylemh 2
  • fix: handle missing of `_/husky.sh` use-case

    fix: handle missing of `_/husky.sh` use-case

    Hello there 👋🏽

    At my company, especially in big repositories, we encountered a lot of cases when a developer's machine has already set his hooks, but the file _/husky.sh has moved or not exists. For example when migrating between husky versions and the place of _/husky.sh changed.

    On this PR, the file will check for the existence of _/husky.sh and if not exists it will install the file through husky install. In case the husky package is not installed yet (on the node_modules) we set the || exist 0

    Another option is to set npx husky install instead of husky install || exit 0, what do you think? At the moment, at my company, we set the sensitive repositories to work with husky install || exit 0 and it really reduced the questions of developers stuck while trying to pull from other branches where they got breaking changes in husky setup.

    opened by Titan196 1
Releases(v8.0.3)
  • v8.0.3(Jan 3, 2023)

  • v8.0.2(Nov 8, 2022)

  • v8.0.1(May 9, 2022)

  • v8.0.0(May 8, 2022)

    What's Changed

    Feats

    • feat: add husky - prefix to logged global error messages by @joshbalfour in https://github.com/typicode/husky/pull/1092
    • feat: show PATH when command not found to improve debuggability
    • feat: drop Node 12 support
    • feat: skip install if $HUSKY=0

    Fixes

    • fix: hook script use /usr/bin/env sh instead of direct path of sh by @skhaz in https://github.com/typicode/husky/pull/1051
    • fix: actually set 'husky_skip_init' as readonly in ./husky.sh by @hyperupcall in https://github.com/typicode/husky/pull/1104
    • fix: force basename/dirname to treat $0 as an argument by @mataha in https://github.com/typicode/husky/pull/1132
    • fix: remove git.io links by @renbaoshuo in https://github.com/typicode/husky/pull/1136

    Docs

    • docs: fix uninstall via npm by @pddpd in https://github.com/typicode/husky/pull/1033
    • docs: add dog emoji as favicon by @jamiehaywood in https://github.com/typicode/husky/pull/1095
    • docs: replace deprecated npx --no-install option with npx --no by @sibiraj-s in https://github.com/typicode/husky/pull/1070
    • docs: add pnpm installation by @MohamadKh75 in https://github.com/typicode/husky/pull/1139

    Chore

    • chore: update workflows by @tiziodcaio in https://github.com/typicode/husky/pull/1125
    Source code(tar.gz)
    Source code(zip)
  • v7.0.4(Oct 21, 2021)

  • v7.0.2(Aug 25, 2021)

  • v7.0.1(Jul 6, 2021)

  • v7.0.0(Jul 1, 2021)

  • v6.0.0(Mar 29, 2021)

    After being in early access for Open Source projects and Sponsors for a limited time, I'm happy to announce that husky 6 is MIT again and can be freely used in commercial projects! 🎉

    Many thanks to the Open Source projects and Companies which have switched to/sponsored the new husky during this period!

    OSS is my full-time job, please consider sponsoring the development of husky on GitHub sponsors or Open Collective. Thank you!

    Breaking change

    • husky init has been moved to its own package (npx husky-init)

    Added

    • Programmatically use husky: require('husky')
    • TypeScript definitions

    Migrating from husky 4

    Husky 6 contains breaking changes. If you're coming from v4, npm install husky@6 won't be enough.

    Recommended: see husky-4-to-6 CLI to automatically migrate your config. There's also a dedicated section in the docs.

    If you're curious why config has changed, you may be interested in reading: https://blog.typicode.com/husky-git-hooks-javascript-config/

    Also Husky 6 follows official npm and Yarn best practices regarding autoinstall. It's recommended to use prepare script instead (see usage in docs).

    Source code(tar.gz)
    Source code(zip)
  • v5.2.0(Mar 21, 2021)

    • Add set command to replace hooks (husky set .husky/pre-commit cmd)
    • Update add command to append command (husky add .husky/pre-commit cmd)
    • Improve error messages
    Source code(tar.gz)
    Source code(zip)
  • v5.1.3(Mar 2, 2021)

  • v5.1.2(Mar 1, 2021)

  • v5.1.1(Feb 22, 2021)

  • v5.1.0(Feb 21, 2021)

  • v5.0.9(Feb 8, 2021)

    • fix(install): do not fail if not inside a Git directory (closes #851)

    See https://github.com/typicode/husky/releases/tag/v5.0.0 for v5 release notes

    Source code(tar.gz)
    Source code(zip)
  • v5.0.8(Jan 28, 2021)

  • v5.0.7(Jan 27, 2021)

  • v4.3.8(Jan 15, 2021)

  • v4.3.7(Jan 7, 2021)

  • v4.3.6(Dec 13, 2020)

  • v5.0.6(Dec 11, 2020)

  • v5.0.5(Dec 11, 2020)

  • v4.3.5(Dec 11, 2020)

  • v4.3.4(Dec 5, 2020)

  • v5.0.0(Nov 16, 2020)

    👉 See https://typicode.github.io/husky for breaking changes and new installation instructions.

    Note about the license

    Husky 5 is released under The Parity Public License.

    It doesn't affect you if you're using husky in an Open Source project or if you're a sponsor. You're free to use it as usual and I hope you'll enjoy this new release ❤️

    If you're using husky in a commercial project, you may want to consider becoming a sponsor to support the project. You can also try it for 30 days.

    This is only for a limited time, husky will be MIT again later.

    Migrating

    Important Husky v5 brings a lot of improvements but is also very different from v4. Git hooks won't work if you only upgrade husky dependency, existing config needs to be migrated too.

    The best way to switch to v5 is to follow the new installation instructions and migrate existing hooks command using husky add.

    Source code(tar.gz)
    Source code(zip)
  • v5.0.0-alpha.5(Sep 22, 2020)

  • v4.3.0(Sep 7, 2020)

  • v4.2.5(Apr 9, 2020)

  • v4.2.4(Apr 9, 2020)

    • When Node version is unsupported, log actual version in addition to the error message #701
    • Fix: support cnpm package manager #687
    • Fix: always use sh to run scripts and avoid inconsistencies #707
    • Fix: don't throw error if files are already removed during uninstall #708
    Source code(tar.gz)
    Source code(zip)
  • v4.2.3(Feb 12, 2020)

Installing husky made easy as woof!

auto-husky Installing husky made easy as woof! ?? ?? Table of contents ?? Installation ?? Usage ?? Versioning ?? Installation You can install the pack

G.Script 24 Jun 28, 2022
React.js todo app with authorization, Testing: Cypress(e2e), UI (Chakra UI), Eslint, prettier, git hooks

React TypeScript template with Vite This is a React + TypeScript boilerplate built with Vite. What's inside? ReactJS Vite TypeScript Jest Testing Libr

Vladislav 2 Jan 28, 2022
📋 React Hooks for forms validation (Web + React Native)

English | 繁中 | 简中 | 日本語 | 한국어 | Français | Italiano | Português | Español | Русский | Deutsch | Türkçe Features Built with performance and DX in mind

React Hook Form 32.4k Dec 29, 2022
Fully typed hooks and utility functions for the React Native StyleSheet API

react-native-style-utilities Fully typed hooks and utility functions for the React Native StyleSheet API npm i react-native-style-utilities ESLint Set

Marc Rousavy 73 Dec 17, 2022
Simple Git (Github) CLI made in Node.js

nagit Simple Git (Github) CLI made in Node.js Quickstart The CLI is self-documented, just follow the steps to perform a commit. npm install -g nagit n

Nacho Aldama 8 Nov 10, 2022
This Login Form made using React hooks , React Js , Css, Json. This form have 3 inputs, it also validate those inputs & it also having length limitations.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Yogesh Sharma 0 Jan 3, 2022
graphql-codegen plugin to generate type-safe, easy-to use hooks for Flutter

graphql-codegen-flutter-artemis-hooks This is graphql-codegen plugin to generate type-safe, easy-to use Flutter artemis hooks. For further detail, see

seya 18 Jan 2, 2023
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native Visit our website at vue-native.io or read the official documentation here. Build native mobile apps using Vue Vue Native is a framework to

GeekyAnts 8.4k Jan 6, 2023
Build performant, native and cross-platform desktop applications with native Vue + powerful CSS like styling.🚀

Vue NodeGui Build performant, native and cross-platform desktop applications with Vue. ?? Vue NodeGUI is powered by Vue ?? and Qt5 ?? which makes it C

NodeGui 765 Dec 30, 2022
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!

toastify-react-native ?? toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense! De

Zahid Ali 29 Oct 11, 2022
null 136 Dec 30, 2022
Next-level academia! Repository for the Native Overleaf project, attempting to integrate Overleaf with native OS features for macOS, Linux and Windows.

Native Overleaf Overleaf is a fantastic webtool for writing and cooperating on LaTeX documents. However, would it not be even better if it were to beh

Floris-Jan Willemsen 40 Dec 18, 2022
A pure JavaScript implementation of git for node and browsers!

isomorphic-git isomorphic-git is a pure JavaScript reimplementation of git that works in both Node.js and browser JavaScript environments. It can read

isomorphic-git 6.7k Jan 4, 2023
A JavaScript implementation of Git.

JS-Git This project is a collection of modules that helps in implementing git powered applications in JavaScript. The original purpose for this is to

Tim Caswell 3.8k Dec 31, 2022
Git commit CLI

commitme Based on this gist by @gustavopch Installation You can install this on your package using npm i -D commitme or run it once using npx commitme

Roz 7 Jun 6, 2021
Repository for hands on practice in Git and GitHub workshop

Git and Github Workshop Jan 2022 Successful contributors ✨ of this project will be featured on the GDSC website so as to bring attraction and learn vi

IIIT Vadodara Open Source 2 Feb 10, 2022
here in this git repo you will get react js basic layout, having in responsive mode.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 3 Feb 23, 2022
Visualize the Directed Acyclic Graph that Git creates to connect Commit, Tree and Blob objects internally.

Git Graph Visualize the Directed Acyclic Graph that Git creates to connect Commit, Tree and Blob objects. Hosted at HarshKapadia2.github.io/git-graph.

Harsh Kapadia 15 Aug 21, 2022
Get a diff view of your Obsidian Sync, File Recovery and Git version history

Version History Diff (for Sync and File Recovery Core plugins and Git) Note This plugin uses private APIs, so it may break at any time. Use at your ow

null 39 Dec 26, 2022