I do not know about this rule but you should check out the Settings section in your GitHub project - there are actually settings that can be used to guard against commiting to the master branch.
There are branch protection rules that you can use to guard individual branches:
Defining the mergeability of pull requests - User Documentation[
^]
You can create a branch when you commit your code. Just make sure you are on the correct branch when you commit
-> when you do that you should realize that you are on the master branch - you can still create a local branch before commiting it - then when you publish - you will publish to a branch instead of master.