How to Protect Git branch and Enforce Restrictions

August 03, 2018

In previous article: Effective Git Branching Strategy, I discussed Git branching strategy and how you can follow best practices to manage your code and builds.

In this article, I will show how you can protect your git branches and restrict them by implementing the best practices.

Create Stage Branch

Open your Master branch. On left hand drop down, you can see only Master branch. Start typing “stage”, and it will give you an option to create that branch. See image below:

Create Stage branch from Master

Protect Your branches

Here, we are going to restrict our two branches: master and stage for two things:

  1. Any code merge will require code review
  2. Only specific person can merge the code
  • Click on Settings tab on your repository.
  • Click on Branches section from left side menu.

Protect branches

  • Click on Branch Protection Rules, and click on Master:

Branch protection rules

Check on Two options: “Protect this branch”, and “Restrict who can push to this branch”, and do appropriate settings: Branch protection rules

Click on Save changes.

Similarly do this for Stage branch.

Similar Posts

Latest Posts