{"id":13495016,"url":"https://github.com/toplenboren/simple-git-hooks","last_synced_at":"2025-05-12T13:17:28.862Z","repository":{"id":37627248,"uuid":"338652909","full_name":"toplenboren/simple-git-hooks","owner":"toplenboren","description":"A simple git hooks manager for small projects","archived":false,"fork":false,"pushed_at":"2025-04-23T17:58:40.000Z","size":261,"stargazers_count":1470,"open_issues_count":16,"forks_count":47,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-12T13:17:06.925Z","etag":null,"topics":["git","git-hooks","hook","hooks-manager","pre-commit","pre-push"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toplenboren.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-13T19:30:46.000Z","updated_at":"2025-05-12T00:38:12.000Z","dependencies_parsed_at":"2024-01-14T19:12:25.132Z","dependency_job_id":"d60247a2-0aa2-42fc-b91c-c6b2e7a4e6c8","html_url":"https://github.com/toplenboren/simple-git-hooks","commit_stats":{"total_commits":154,"total_committers":16,"mean_commits":9.625,"dds":"0.44805194805194803","last_synced_commit":"499a998df94238679bd61c3e2e539597d8f1edf2"},"previous_names":["toplenboren/simple-pre-commit"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplenboren%2Fsimple-git-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplenboren%2Fsimple-git-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplenboren%2Fsimple-git-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toplenboren%2Fsimple-git-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toplenboren","download_url":"https://codeload.github.com/toplenboren/simple-git-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745196,"owners_count":21957319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","git-hooks","hook","hooks-manager","pre-commit","pre-push"],"created_at":"2024-07-31T19:01:30.389Z","updated_at":"2025-05-12T13:17:28.808Z","avatar_url":"https://github.com/toplenboren.png","language":"JavaScript","readme":"# simple-git-hooks\n\n![](https://img.shields.io/badge/dependencies-zero-green) [![Tests](https://github.com/toplenboren/simple-git-hooks/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/toplenboren/simple-git-hooks/actions/workflows/tests.yml)\n\nA tool that lets you easily manage git hooks\n\n\u003e The package was recently renamed from `simple-pre-commit`.\n\n\u003e See **Releases** for the `simple-pre-commit` documentation and changelog\n\n- Zero dependency\n- Small configuration (1 object in package.json)\n- Lightweight:\n\n  | Package                       | Unpacked size | With deps |\n  |-------------------------------|--------------|-----------|\n  | husky v4 `4.3.8`              | `53.5 kB`    | `~1 mB`   |\n  | husky v8 `8.0.3`              | `6.44 kB`    | `6.44 kB` |\n  | pre-commit `1.2.2`            | `~80 kB`     | `~850 kB` |\n  | **simple-git-hooks** `2.11.0` | `10.9 kB`    | `10.9 kB` |\n\n### Who uses simple-git-hooks?\n\n- [Autoprefixer](https://github.com/postcss/autoprefixer)\n- [PostCSS](https://github.com/postcss/postcss.org)\n- [Browserslist](https://github.com/browserslist/browserslist)\n- [Nano ID](https://github.com/ai/nanoid)\n- [Size Limit](https://github.com/ai/size-limit)\n- [Storeon](https://github.com/storeon/storeon)\n- [Directus](https://github.com/directus/directus)\n- [Vercel/pkg](https://github.com/vercel/pkg)\n- More, see [full list](https://github.com/toplenboren/simple-git-hooks/network/dependents?package_id=UGFja2FnZS0xOTk1ODMzMTA4)\n\n### What is a git hook?\n\nA 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`.\n\nIf the execution of a git hook fails, then the git action aborts.\n\nFor 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`.\n\nCheck out [lint-staged](https://github.com/okonet/lint-staged#readme). It works really well with `simple-git-hooks`.\n\nYou can look up about git hooks on the [Pro Git book](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks).\n\n### When to use it\n\n`simple-git-hooks` works well for small-sized projects when you need quickly set up hooks and forget about it.\n\nHowever, this package requires you to manually apply the changes to git hooks. If you update them often, this is probably not the best choice.\n\nAlso, this package allows you to set only one command per git hook.\n\nIf you need multiple verbose commands per git hook, flexible configuration or automatic update of git hooks, please check out the other packages:\n\n- [Lefthook](https://github.com/Arkweid/lefthook)\n- [husky](https://typicode.github.io/husky/)\n- [pre-commit](https://github.com/pre-commit/pre-commit)\n\n## Usage\n\n### Add simple-git-hooks to the project\n\n1. Install simple-git-hooks as a dev dependency:\n\n   ```sh\n   npm install simple-git-hooks --save-dev\n   ```\n\n2. Add `simple-git-hooks` to your `package.json`. Fill it with git hooks and the corresponding commands.\n\n   For example:\n\n   ```jsonc\n   {\n     \"simple-git-hooks\": {\n       \"pre-commit\": \"npx lint-staged\",\n       \"pre-push\": \"npm run format\",\n\n       // All unused hooks will be removed automatically by default\n       // but you can use the `preserveUnused` option like following to prevent this behavior\n\n       // if you'd prefer preserve all unused hooks\n       \"preserveUnused\": true,\n\n       // if you'd prefer preserve specific unused hooks\n       \"preserveUnused\": [\"commit-msg\"]\n     }\n   }\n   ```\n\n   This configuration is going to run all linters on every `commit` and formatter on `push`.\n\n   \u003e There are more ways to configure the package. Check out [Additional configuration options](#additional-configuration-options).\n\n3. Run the CLI script to update the git hooks with the commands from the config:\n\n   ```sh\n   npx simple-git-hooks\n   ```\n\nNow all the git hooks are created.\n\n### Update git hooks command\n\n1. Change the configuration.\n\n2. Run `npx simple-git-hooks` **from the root of your project**.\n\nNote for **yarn2** users: Please run `yarn dlx simple-git-hooks` instead of the command above. More info on [dlx](https://yarnpkg.com/cli/dlx)\n\nNote for **yarn1** users: Please run `ynpx simple-git-hooks` instead of the command above. More info on [ynpx](https://npm.io/package/ynpx)\n\nNote that you should manually run `npx simple-git-hooks` **every time you change a command**.\n\n### Additional configuration options\n\nYou can also add a `.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `.simple-git-hooks.mjs`, `simple-git-hooks.cjs`, `simple-git-hooks.js`, `simple-git-hooks.mjs`, `.simple-git-hooks.json` or `simple-git-hooks.json` file to the project and write the configuration inside it.\n\nThis way `simple-git-hooks` configuration in `package.json` will not take effect any more.\n\n`.simple-git-hooks.cjs`, `.simple-git-hooks.js`, `.simple-git-hooks.mjs` or `simple-git-hooks.cjs`, `simple-git-hooks.js`, `simple-git-hooks.mjs` should look like the following.\n\n#### CommonJS\n\n```js\nmodule.exports = {\n  \"pre-commit\": \"npx lint-staged\",\n  \"pre-push\": \"npm run format\",\n};\n```\n\n\n#### ES Modules\n\n```js\nexport default {\n  \"pre-commit\": \"npx lint-staged\",\n  \"pre-push\": \"npm run format\",\n};\n```\n\n`.simple-git-hooks.json` or `simple-git-hooks.json` should look like the following.\n\n```json\n{\n  \"pre-commit\": \"npx lint-staged\",\n  \"pre-push\": \"npm run format\"\n}\n```\n\nIf 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`.\n\n### Note for `npm` package developers\n\nPlease do not add `postinstall: \"npx simple-git-hooks\"` script in your `package.json`. Or at least remove it before `npm publish`\n\nIt causes errors for end users of your package\n\n### Uninstall simple-git-hooks\n\n\u003e Uninstallation will remove all the existing git hooks.\n\n```sh\nnpm uninstall simple-git-hooks\n```\n\n## Common issues\n\n### I want to skip git hooks!\n\nIf 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.\n\n```sh\nexport SKIP_INSTALL_SIMPLE_GIT_HOOKS=1\n\nnpm install simple-git-hooks --save-dev\n```\n\nOr if you only need to bypass hooks for a single git operation, you should use `--no-verify` option\n\n```sh\ngit commit -m \"commit message\" --no-verify # -n for shorthand\n```\n\nyou can read more about it here https://bobbyhadz.com/blog/git-commit-skip-hooks#skip-git-commit-hooks\n\n\nIf 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.\n\n```sh\n# Set the environment variable\nexport SKIP_SIMPLE_GIT_HOOKS=1\n\n# Subsequent Git commands will skip the hooks\ngit add .\ngit commit -m \"commit message\"  # pre-commit hooks are bypassed\ngit push origin main  # pre-push hooks are bypassed\n```\n\n### Skipping Hooks in 3rd party git clients\n\nIf 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.\n\nIf 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.\n\nIf these options are not available, you may need to resort to using the terminal for skipping hooks.\n\n### I am getting \"npx: command not found\" error in a GUI git client\n\nThis happens when using a node version manager such as `nodenv`, `nvm`, `mise` which require\ninit script to provide project-specific node binaries.\n\nCreate init script in `~/.simple-git-hooks.rc` that should be executed prior to git hooks.\nPlease refer to your node manager documentation for details. For example, for mise, that will\nbe:\n\n```sh\nexport PATH=\"$HOME/.local/share/mise/shims:$PATH\"\n```\n\nAdd `SIMPLE_GIT_HOOKS_RC` global environment variable pointing to that new script. For\nexample, on macOS, add this to `~/.zshenv`:\n\n```sh\nexport SIMPLE_GIT_HOOKS_RC=\"$HOME/.simple-git-hooks.rc\"\n```\n","funding_links":[],"categories":["JavaScript","Tools"],"sub_categories":["Project Manage"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoplenboren%2Fsimple-git-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoplenboren%2Fsimple-git-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoplenboren%2Fsimple-git-hooks/lists"}