Gathering detailed insights and metrics for simple-git-hooks
Gathering detailed insights and metrics for simple-git-hooks
Gathering detailed insights and metrics for simple-git-hooks
Gathering detailed insights and metrics for simple-git-hooks
npm install simple-git-hooks
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,351 Stars
242 Commits
43 Forks
5 Watching
2 Branches
21 Contributors
Updated on 28 Nov 2024
JavaScript (99.84%)
Shell (0.16%)
Cumulative downloads
Total Downloads
Last day
-3.3%
31,227
Compared to previous day
Last week
-0.4%
181,694
Compared to previous week
Last month
14.4%
769,861
Compared to previous month
Last year
48.8%
6,852,853
Compared to previous year
No dependencies detected.
A tool that lets you easily manage git hooks
The package was recently renamed from
simple-pre-commit
.
See Releases for the
simple-pre-commit
documentation and changelog
Zero dependency
Small configuration (1 object in package.json)
Lightweight:
Package | Unpacked size | With deps |
---|---|---|
husky v4 4.3.8 | 53.5 kB | ~1 mB |
husky v8 8.0.3 | 6.44 kB | 6.44 kB |
pre-commit 1.2.2 | ~80 kB | ~850 kB |
simple-git-hooks 2.11.0 | 10.9 kB | 10.9 kB |
A git hook is a command or script that is going to be run every time you perform a git action, like git commit
or git push
.
If the execution of a git hook fails, then the git action aborts.
For example, if you want to run linter
on every commit to ensure code quality in your project, then you can create a pre-commit
hook that would call npx lint-staged
.
Check out lint-staged. It works really well with simple-git-hooks
.
You can look up about git hooks on the Pro Git book.
simple-git-hooks
works well for small-sized projects when you need quickly set up hooks and forget about it.
However, this package requires you to manually apply the changes to git hooks. If you update them often, this is probably not the best choice.
Also, this package allows you to set only one command per git hook.
If you need multiple verbose commands per git hook, flexible configuration or automatic update of git hooks, please check out the other packages:
Install simple-git-hooks as a dev dependency:
1npm install simple-git-hooks --save-dev
Add simple-git-hooks
to your package.json
. Fill it with git hooks and the corresponding commands.
For example:
1{ 2 "simple-git-hooks": { 3 "pre-commit": "npx lint-staged", 4 "pre-push": "npm run format", 5 6 // All unused hooks will be removed automatically by default 7 // but you can use the `preserveUnused` option like following to prevent this behavior 8 9 // if you'd prefer preserve all unused hooks 10 "preserveUnused": true, 11 12 // if you'd prefer preserve specific unused hooks 13 "preserveUnused": ["commit-msg"] 14 } 15}
This configuration is going to run all linters on every commit
and formatter on push
.
There are more ways to configure the package. Check out Additional configuration options.
Run the CLI script to update the git hooks with the commands from the config:
1# [Optional] These 2 steps can be skipped for non-husky users 2git config core.hooksPath .git/hooks/ 3rm -rf .git/hooks 4 5# Update ./git/hooks 6npx simple-git-hooks
Now all the git hooks are created.
Change the configuration.
Run npx simple-git-hooks
from the root of your project.
Note for yarn2 users: Please run yarn dlx simple-git-hooks
instead of the command above. More info on dlx
Note for yarn1 users: Please run ynpx simple-git-hooks
instead of the command above. More info on ynpx
Note that you should manually run npx simple-git-hooks
every time you change a command.
You can also add a .simple-git-hooks.cjs
, .simple-git-hooks.js
, simple-git-hooks.cjs
, simple-git-hooks.js
, .simple-git-hooks.json
or simple-git-hooks.json
file to the project and write the configuration inside it.
This way simple-git-hooks
configuration in package.json
will not take effect any more.
.simple-git-hooks.cjs
, .simple-git-hooks.js
or simple-git-hooks.cjs
, simple-git-hooks.js
should look like the following.
1module.exports = { 2 "pre-commit": "npx lint-staged", 3 "pre-push": "npm run format", 4};
.simple-git-hooks.json
or simple-git-hooks.json
should look like the following.
1{ 2 "pre-commit": "npx lint-staged", 3 "pre-push": "npm run format" 4}
If you need to have multiple configuration files or just your-own configuration file, you install hooks manually from it by npx simple-git-hooks ./my-config.js
.
npm
package developersPlease do not add postinstall: "npx simple-git-hooks"
script in your package.json
. Or at least remove it before npm publish
It causes errors for end users of your package
Uninstallation will remove all the existing git hooks.
1npm uninstall simple-git-hooks
If you need to bypass install hooks at all, for example on CI, you can use SKIP_INSTALL_SIMPLE_GIT_HOOKS
environment variable at the first place.
1export SKIP_INSTALL_SIMPLE_GIT_HOOKS=1 2 3npm install simple-git-hooks --save-dev
Or if you only need to bypass hooks for a single git operation, you should use --no-verify
option
1git commit -m "commit message" --no-verify # -n for shorthand
you can read more about it here https://bobbyhadz.com/blog/git-commit-skip-hooks#skip-git-commit-hooks
If you need to bypass hooks for multiple Git operations, setting the SKIP_SIMPLE_GIT_HOOKS environment variable can be more convenient. Once set, all subsequent Git operations in the same terminal session will bypass the associated hooks.
1# Set the environment variable 2export SKIP_SIMPLE_GIT_HOOKS=1 3 4# Subsequent Git commands will skip the hooks 5git add . 6git commit -m "commit message" # pre-commit hooks are bypassed 7git push origin main # pre-push hooks are bypassed
If your client provides a toggle to skip Git hooks, you can utilize it to bypass the hooks. For instance, in VSCode, you can toggle git.allowNoVerifyCommit in the settings.
If you have the option to set arguments or environment variables, you can use the --no-verify option or the SKIP_SIMPLE_GIT_HOOKS environment variable.
If these options are not available, you may need to resort to using the terminal for skipping hooks.
husky
git hooks are not runningWhy is this happening?
Husky might change the core.gitHooks
value to .husky
, this way, git hooks would search .husky
directory instead of .git/hooks/
.
Read more on git configuration in Git book
You can check it by running this command inside of your repo:
git config core.hooksPath
If it outputs .husky
then this is your case
How to fix?
you need to point core.gitHooks
value to your-awesome-project/.git/hooks
. You can use this command:
git config core.hooksPath .git/hooks/
validate the value is set:
git config core.hooksPath
should output: .git/hooks/
Then remove the .husky
folder that are generated previously by husky
.
This happens when using a node version manager such as nodenv
, nvm
, mise
which require
init script to provide project-specific node binaries.
Create init script in ~/.simple-git-hooks.rc
that should be executed prior to git hooks.
Please refer to your node manager documentation for details. For example, for mise, that will
be:
1export PATH="$HOME/.local/share/mise/shims:$PATH"
Add SIMPLE_GIT_HOOKS_RC
global environment variable pointing to that new script. For
example, on macOS, add this to ~/.zshenv
:
1export SIMPLE_GIT_HOOKS_RC="$HOME/.simple-git-hooks.rc"
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 5/19 approved changesets -- score normalized to 2
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
21 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More