Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run pre-commit only on certain branches

I am looking for a configuration in the .pre-commit-config.yaml to exclude pre-commit from being run on certain branches, or to run it only on some branches. I don't know if this feature not implemented, or if I am missing it in the docs.

Thanks!

like image 649
Alex Martínez Ascensión Avatar asked Jan 19 '26 00:01

Alex Martínez Ascensión


1 Answers

Git hooks are just shell scripts that are executed.

So in the script you can do something similar to this:

if [ $(git branch --no-color | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') = "main" ]; then
  # Do checks for main here
fi
like image 199
Mathijs Vogelzang Avatar answered Jan 21 '26 20:01

Mathijs Vogelzang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!