Repository Rulesets are a pretty cool feature in GitHub that allow you to set some rules that contributors have to follow like no force-pushing, linear history (prevents merge commits) and merging via pull requests (no pushing directly to the default branch).
These features enable a coherent and secure way of working within a repository but there is a catch - the feature is only available if you make your repository public or if you have a GitHub Pro, GitHub Team, and GitHub Enterprise Cloud pricing plan.
If you'd rather spend your money on some drinks at a sunny terrace, then you can leverage githooks to implement a simple pre-hook script that checks which branch you are on, right before the git client pushes your commits, and then exit with 1 if it is a protected branch like main or master. For a more technical explanation, feel free to read danso's blog on 'stopping yourself from force-pushing to master' which tries to perform a similar behavior to my personal favorite feature - no pushing directly to the main branch.