Github branch Rules every developer should know

Arian Al Lami
2 min readApr 19, 2023

--

Photo by Roman Synkevych 🇺🇦 on Unsplash

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.

Git adding branch rule

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.

Git require pull request

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”

Git Require status check

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.

--

--

Arian Al Lami
Arian Al Lami

Written by Arian Al Lami

Hi was Front End developer for 6 years, I am now Software Engineer since 5 years+ follow me so can share the tips and tricks I picked in all these years.

No responses yet