Github branch Rules every developer should know
When you are working on your own in your git repo its ok but if you are working as part of the team you need to have branch protection otherwise any one will be able to commit directly to your repo, they can commit a virus, or commit delete of all the important code without any checks so please read below to make your repo secure.
Login to your repo and go to the settings click on the branch from the left hand menu click add rule.
Require Pull Request:
Click on Require pull request that will make sure no one can directly commit to your master branch they would have to raise pull request.
Click on require approval best practice is to have 2 approval it means two developer would have to check the code and approve it before it get merge to master.
But we can’t always rely on humans we make errors so definitely do the below to make your branch more secure, add “Require status checks”
click on the require status check and in the search bar type the checks you already have in your repo for example Lint, Built-test (unit tests) SonarCloud to check the code coverage. NOTE: the name and types of tests on each repo will be different above image is an example only, search for the names you have set in your package.json scripts section.
the above check will run on each Pull request and if the lint fails or test coverage is low or if the build test fails then the engineer would get the error and they would have to work on their branch and fix them.
Thats all from on this topic please clap or follow, it will encourage me to write more articles. Happy coding.