Let's say you want to disable commits to the main branch of one of your GitHub repos. Fortunately, this is very easy to configure.
Then let's go to the repository Settings > Rules > Rulesets and let's create a rule set. In the Ruleset checkmark Require a pull request before merging. That's all there really is to it.
You probably want to apply this ruleset to only the main/master/default branch.
Now, if you attempt to commit to the main branch, you'll see a message like this.