{"id":1586,"date":"2019-04-13T00:00:00","date_gmt":"2019-04-12T22:00:00","guid":{"rendered":"https:\/\/demo.sidekick.be\/itenium\/git-hooks-with-husky\/"},"modified":"2025-11-28T13:31:45","modified_gmt":"2025-11-28T12:31:45","slug":"git-hooks-with-husky","status":"publish","type":"post","link":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/","title":{"rendered":"Git Hooks with Husky"},"content":{"rendered":"<h1 id=\"hooks\">Hooks<\/h1>\n<blockquote>\n<p><strong>git hooks<\/strong><br \/> Run a program before certain points in gits execution.<\/p>\n<\/blockquote>\n<p>They are defined in <code>.githooks<\/code>. <!-- (config: `core.hooksPath`) --><br \/> You can find some example files in that directory. Remove their <code>.sample<\/code> suffix to test them out.<\/p>\n<h1 id=\"husky\">Husky<\/h1>\n<p>Hooks are saved locally and not pushed to the remote. Husky allows you to easily make the git hooks part of the repository itself.<\/p>\n<pre><code>npm install husky --save-dev\n<\/code><\/pre>\n<p>Add to <code>package.json<\/code><\/p>\n<pre><code class=\"language-json\">{\n  \"husky\": {\n    \"hooks\": {\n      \"pre-push\": \"bash prepush.sh\",\n      \"pre-commit\": \"npm run lint\"\n    }\n  }\n}\n<\/code><\/pre>\n<p>It\u2019s also possible to put the json (without the <code>husky<\/code> node) in a <code>.huskyrc<\/code> or <code>.huskyrc.json<\/code> file.<\/p>\n<h2 id=\"prepushsh\">prepush.sh<\/h2>\n<p>Prepush script that works around the frontend project <code>package.json<\/code> not being in the root of the git repository.<\/p>\n<pre><code class=\"language-bash\">#!\/bin\/sh\n\n# Path Juggling\noriginalPath=`pwd`\nif [ \"`git rev-parse --show-cdup`\" != \"\" ]; then cd `git rev-parse --show-cdup`; fi\ncd .\/frontend-project-folder\/\n\n# Linting\nnpm run lint\nif [ $? -ne 0 ]; then\n    cd $originalPath\n    exit -1\nfi\n\n# Testing\nnpm test\nif [ $? -ne 0 ]; then\n  cd $originalPath\n  exit -1\nfi\n\n# Build\nnpm run build\nhasBuildErrors=$?\n\ncd $originalPath\nexit $hasBuildErrors\n<\/code><\/pre>\n<h2 id=\"other\">Other<\/h2>\n<p>More control with <code>.huskyrc.js<\/code> and environment variables.<\/p>\n<pre><code class=\"language-js\">const tasks = arr =&gt; arr.join(' &amp;&amp; ');\n\nmodule.exports = {\n  'hooks': {\n    'pre-commit': tasks([\n      'echo $HUSKY_GIT_PARAMS',\n      'echo $HUSKY_GIT_STDIN',\n      'echo $HUSKY_DEBUG',\n      'echo $HUSKY_SKIP_INSTALL'\n    ])\n  }\n};\n<\/code><\/pre>\n<h1>Extras<\/h1>\n<p><b>Other interesting reads<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/git-scm.com\/docs\/githooks\">Official githooks documentation<\/a><\/li>\n<\/ul>\n<h1> Package Versions <i class=\"fa fa-info-circle\" style=\"float: right; color: cornflowerblue; font-size: 28px\" title=\"Package versions used for this post and in the accompanying code on Github\"><\/i><\/h1>\n<div><a href=\"https:\/\/github.com\/typicode\/husky\" class=\"github\"><img decoding=\"async\" src=\"https:\/\/img.shields.io\/github\/stars\/typicode\/husky.svg?style=social&#038;label=Star\" \/><\/a><a href=\"https:\/\/github.com\/typicode\/husky\">typicode\/husky<\/a>: v1.3.1 <\/div>\n","protected":false},"excerpt":{"rendered":"<p class=\"notice\"><strong>Update for Husky v9<\/strong><br \/> A lot has changed in Husky since this blog post. See the <a href=\"https:\/\/itenium.be\/blog\/dev-setup\/git-hooks-with-husky-v9\">2024 update of this article<\/a> instead!<\/p>\n<p>Avoid pushing changes that break the build with githooks and Husky.<\/p>\n<p><a href=\"https:\/\/github.com\/typicode\/husky\" class=\"github\"><img decoding=\"async\" src=\"https:\/\/img.shields.io\/github\/stars\/typicode\/husky.svg?style=social&amp;label=Star\" \/><\/a><a href=\"https:\/\/github.com\/typicode\/husky\">typicode\/husky<\/a>: \ud83d\udc3a Git hooks made easy<\/p>\n","protected":false},"author":1,"featured_media":2078,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[26],"class_list":["post-1586","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev-setup","tag-git"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Git Hooks with Husky - Itenium<\/title>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Git Hooks with Husky - Itenium\" \/>\n<meta property=\"og:description\" content=\"Update for Husky v9 A lot has changed in Husky since this blog post. See the 2024 update of this article instead!Avoid pushing changes that break the build with githooks and Husky.typicode\/husky: \ud83d\udc3a Git hooks made easy\" \/>\n<meta property=\"og:url\" content=\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/\" \/>\n<meta property=\"og:site_name\" content=\"Itenium\" \/>\n<meta property=\"article:published_time\" content=\"2019-04-12T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-28T12:31:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"360\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Usdevelop\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Usdevelop\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/\",\"name\":\"Git Hooks with Husky - Itenium\",\"isPartOf\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg\",\"datePublished\":\"2019-04-12T22:00:00+00:00\",\"dateModified\":\"2025-11-28T12:31:45+00:00\",\"author\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\"},\"breadcrumb\":{\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg\",\"contentUrl\":\"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg\",\"width\":360,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/demo.sidekick.be\/itenium\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Git Hooks with Husky\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#website\",\"url\":\"https:\/\/demo.sidekick.be\/itenium\/\",\"name\":\"Itenium\",\"description\":\"We build software. We build careers.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022\",\"name\":\"Usdevelop\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g\",\"caption\":\"Usdevelop\"},\"sameAs\":[\"https:\/\/demo.sidekick.be\/itenium\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Git Hooks with Husky - Itenium","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Git Hooks with Husky - Itenium","og_description":"Update for Husky v9 A lot has changed in Husky since this blog post. See the 2024 update of this article instead!Avoid pushing changes that break the build with githooks and Husky.typicode\/husky: \ud83d\udc3a Git hooks made easy","og_url":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/","og_site_name":"Itenium","article_published_time":"2019-04-12T22:00:00+00:00","article_modified_time":"2025-11-28T12:31:45+00:00","og_image":[{"width":360,"height":300,"url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg","type":"image\/jpeg"}],"author":"Usdevelop","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Usdevelop","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/","url":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/","name":"Git Hooks with Husky - Itenium","isPartOf":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#website"},"primaryImageOfPage":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage"},"image":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage"},"thumbnailUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg","datePublished":"2019-04-12T22:00:00+00:00","dateModified":"2025-11-28T12:31:45+00:00","author":{"@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022"},"breadcrumb":{"@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#primaryimage","url":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg","contentUrl":"https:\/\/demo.sidekick.be\/itenium\/wp-content\/uploads\/2025\/11\/git-hooks-husky.jpg","width":360,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/demo.sidekick.be\/itenium\/blog\/dev-setup\/git-hooks-with-husky\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/demo.sidekick.be\/itenium\/"},{"@type":"ListItem","position":2,"name":"Git Hooks with Husky"}]},{"@type":"WebSite","@id":"https:\/\/demo.sidekick.be\/itenium\/#website","url":"https:\/\/demo.sidekick.be\/itenium\/","name":"Itenium","description":"We build software. We build careers.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/demo.sidekick.be\/itenium\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/6ab401ce01e858184ee4a8667fe0f022","name":"Usdevelop","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/demo.sidekick.be\/itenium\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cc8cf9b9e9d5bbe7e8d247907cc9ac8457bbfa2854b52eaddf6529adfe88ceab?s=96&d=mm&r=g","caption":"Usdevelop"},"sameAs":["https:\/\/demo.sidekick.be\/itenium"]}]}},"_links":{"self":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/comments?post=1586"}],"version-history":[{"count":3,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1586\/revisions"}],"predecessor-version":[{"id":2294,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/posts\/1586\/revisions\/2294"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media\/2078"}],"wp:attachment":[{"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/media?parent=1586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/categories?post=1586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demo.sidekick.be\/itenium\/wp-json\/wp\/v2\/tags?post=1586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}