- Notifications
You must be signed in to change notification settings - Fork0
coderbk197/git-scm-hooks
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A git hook is a command or script that is going to be run every time you perform a git action, likegit commit orgit push.
If the execution of a git hook fails, then the git action aborts.
For example, if you want to runlinter on every commit to ensure code quality in your project, then you can create apre-commit hook that would callnpx lint-staged.
Check outlint-staged. It works really well withgit-scm-hooks.
You can look up about git hooks on thePro Git book.
git-scm-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 git-scm-hooks as a dev dependency:
npm install git-scm-hooks@latest --save-dev
Add
git-hooksto yourpackage.json. Fill it with git hooks and the corresponding commands.For example:
{"git-hooks": {"pre-commit":"npx lint-staged","pre-push":"cd ../../ && npm run format",// All unused hooks will be removed automatically by default// but you can use the `preserveUnused` option like following to prevent this behavior// if you'd prefer preserve all unused hooks"preserveUnused":true,// if you'd prefer preserve specific unused hooks"preserveUnused": ["commit-msg"] }}This configuration is going to run all linters on every
commitand formatter onpush.There are more ways to configure the package. Check outAdditional configuration options.
Run the CLI script to update the git hooks with the commands from the config:
# [Optional] These 2 steps can be skipped for non-husky usersgit config core.hooksPath .git/hooks/rm -rf .git/hooks# Update ./git/hooksnpx git-scm-hooks
Now all the git hooks are created.
Change the configuration.
Run
npx git-scm-hooksfrom the root of your project.
Note foryarn2 users: Please runyarn dlx git-scm-hooks instead of the command above. More info ondlx
Note that you should manually runnpx git-scm-hooksevery time you change a command.
{"pre-commit":"npx lint-staged","pre-push":"cd ../../ && npm run format"}If you need to have multiple configuration files or just your-own configuration file, you install hooks manually from it bynpx git-scm-hooks ./my-config.js.
Uninstallation will remove all the existing git hooks.
npm uninstall git-scm-hooks
You should use--no-verify option
https://bobbyhadz.com/blog/git-commit-skip-hooks#skip-git-commit-hooks
Why is this happening?
Husky might change thecore.gitHooks value to.husky, this way, git hooks would search.husky directory instead of.git/hooks/.
Read more on git configuration inGit 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 pointcore.gitHooks value toyour-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 byhusky.
About
git-scm-hooks
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Languages
- TypeScript89.6%
- JavaScript10.4%