59

I have pre-push hook implemented with Husky. Now I wanna remove it.

Problem is that after yarn remove husky git hooks are still there inside .git/hooks.

Because of that I get this error every time I want to commit or switch branch or commit, thus commiting is not even possible -->

.git/hooks/pre-commit: line 6: node_modules/run-node/run-node: No such file or directory

I know I can always delete every hook inside .git/hooks but how I can push this changes remotely? How not to force my teammates do the same thing?

Also I know I can commit using -n flag but still I would like not to do it.

Nikola Mitic
  • 1,298
  • 3
  • 11
  • 23

5 Answers5

90

Assuming you have no non-husky hooks, you might want to keep:

rm -f .git/hooks/*

every file inside ".git/hooks/" is either a git-hook or ignored by git. By removing everything inside, you'll get rid of all hooks, and restore the default behavior.

By default there are example-hooks in there, but except for being examples they serve no purpose, so you can delete them.

wotanii
  • 2,470
  • 20
  • 38
  • 7
    I also recommend to run [`git init`](https://stackoverflow.com/a/10794187/7976758) in the repository to recreate default hook samples. – phd Aug 30 '18 at 12:23
  • 1
    Cool. But what about pushing this change to remote branch that will later me merged to develop? I don't want to force everyone to remove it manually? Could be that I don't understand something here. – Nikola Mitic Aug 30 '18 at 12:23
  • 2
    Everything inside the `.git` folder is purely local. You have no way to change hooks on your teammates machines. – kowsky Aug 30 '18 at 12:53
  • @Nikola Mitic everything you do inside this folder happens only locally. Depending on your hooks, you might want to repeat the process on all remotes. (But then you might ask yourself, how the hooks got into the remotes in the first place, since you can't use the worktree to change files in .git/hooks) – wotanii Aug 30 '18 at 12:53
  • 1
    A 'less aggressive/assuming' version of this, would be to only remove the hooks that use husky. This does the trick: `rm \`grep -l husky .git/hooks/*\`` – spechter Feb 04 '23 at 05:01
27

I think it's better to keep all *.sample in .git/hooks

To remove git hooks who come husky :

  • First, go to hooks directory
cd .git/hooks
  • Secondly, keep all *.sample files and remove others
ls | grep \.sample -v | xargs rm
Renan Bronchart
  • 926
  • 17
  • 24
9
git config --unset core.hooksPath
Ben Kauffman
  • 396
  • 4
  • 5
7

The Husky documentation recommends doing it this way:

npm uninstall husky && git config --unset core.hooksPath

or

yarn remove husky && git config --unset core.hooksPath
clemlatz
  • 7,543
  • 4
  • 37
  • 51
jQN
  • 459
  • 6
  • 5
  • 1
    The link to the docs is broken, but the instructions are working as of today (June 2023) – thoroc Jun 06 '23 at 09:25
  • Here is the current link to the docs: [npm](https://typicode.github.io/husky/getting-started.html#uninstall) [yarn](https://typicode.github.io/husky/getting-started.html#uninstall-1) – Anish Aug 10 '23 at 11:52
2

So basically removing remote git hooks is not possible.

The best you can do is to remove your local ones and notify the rest of the team to do the same.

On how to remove git hook locally check @wotanii answer.

Nikola Mitic
  • 1,298
  • 3
  • 11
  • 23