Habits and rules are both concerned with consequences, but they both mitigate those consequences in different ways.
Let's think about a simple example: suppose a person uses a bathroom, but neglects to wash their hands.
A good habit would prevent this, because the person would remember the potential consequences of not washing their hands, namely they might get sick. We can say that good habits are autonomous: only one person is required to remind themself.
A rule would be to punish the person for not washing their hands, and would require another party to enforce such a rule. Therefore, we can say that rules are authoritarian.
It is a simple example, but the main takeaway is that habits are autonomous (self-enforced), while rules are authoritarian (enforced by others).
One consequence of this is that good habits scale better in a team, because those habits do not require a lot of oversight, instead they can be encourage via cultural norms: "this is just how we do things around here".
Secondly, that autonomous culture is much better for morale, as few people enjoys operating in a strict rule-based organisation. There are some examples where that is genuinely required, like for example the military or police, but for software engineering it is complete overkill.
Build good personal habits, demonstrate those to your team, and set the expectation to follow them by highlighting the benefits of good project hygiene.