Enforcing pre-commit hooks
When team works together, it's often natural and best to have pre-commit hooks that aligns style, and basic syntax checks before the code makes it to main branch.
However, enforcing this often becomes a cultural topic, as people have to follow it by practice.
Due to friction and time constraints, developers often tend to do git commits with
--no-verify option which allows them to commit and push code to respective branches without respecting style guide.
Best course of action: Identify why developers have this friction and remove/optimise it. Is pre-commit run taking too long? Can it be solved by making a standard common IDE guide? Etc.
While we can't force behaviour in a diverse set of adults, we can still reach the end goal we intend to. Have only style/syntax code checked in main branch.
To avoid this code getting into main branch,
Disable push to main branches and make it explicitly only via merge request. This also gives a benefit of enforcing code review on everything going to main branch.
Continuous integration comes into play. Write a CI script in github actions/gitlab ci or any other tool of your choice to mandate the execution of pre-commit hooks before merging into main branch.
This would mark the merge request as failure if syntax/commit hooks aren't respected, causing merge request not to be merged.
Eventually developers will get to a state where they run pre-commit hooks.