How to protect your branch in Github?
At Microsoft we have an opportunity to partake in Openhacks in different areas like Infra, DevOps, Data, ML, Containers and the list goes on.. Recently I attended DevOps openhack to strengthen my DevOps skills and this time I used Github instead of Azure DevOps. I wanted to share my learning as I worked through difference challenges.
One of the first challenges was to know how to protect the main branch (or master) from accidental commits.
- Login to your github account
- Click on your repository >> Settings >> Branches
3. Click on “Add rule”,
4. Branch name pattern: master
5. Enable the option Require pull request reviews before merging and specify the number of reviewers. In this case I want the request to be reviewed by at least 1 reviewer before committing to the master branch
That’s it. Your master branch is now protected from accidental commits and it will be reviewed by the named reviewer before committing your changes to the master branch.