It is impossible to override the default git command through git itself, but you can put the following in your .bashrc
:
function git() {
case $* in
commit* ) npm run commit ;; # or yarn commit
* ) command git "$@" ;;
esac
}
This will override the git command if the second argument is "commit", and use the normal git command if not. (The command
ensures that we do not use our function recursively - it will go directly to the git executable, not back to our defined function.)
See here this answer for more information.
Note the warning in the commitizen docs:
NOTE: if you are using precommit hooks thanks to something like husky, you will need to name your script some thing other than "commit" (e.g. "cm": "git-cz"). The reason is because npm-scripts has a "feature" where it automatically runs scripts with the name prexxx where xxx is the name of another script. In essence, npm and husky will run "precommit" scripts twice if you name the script "commit," and the work around is to prevent the npm-triggered precommit script.
I'd recommend yarn cz
/npm run cz
instead.