git|August 03, 2018|1 min read

How to Protect Git branch and Enforce Restrictions

TL;DR

Configure Git branch protection rules to restrict direct commits to important branches like master and stage, enforcing code review and merge best practices.

How to Protect Git branch and Enforce Restrictions

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.

Related Posts

A Practical Guide for better understanding Git Diff

A Practical Guide for better understanding Git Diff

Introduction In this guide, We will get basic understanding of various options…

Drupal 8 Views - How to merge two fields by hiding another field

Drupal 8 Views - How to merge two fields by hiding another field

Introduction You have a view with 4-5 fields to display. Suppose, there are two…

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

How to Git Clone Another Repository from Jenkin Pipeline in Jenkinsfile

Introduction There are some cases, where I need another git repository while…

Microsoft Visual Studio Code - Must-have extensions for Developers

Microsoft Visual Studio Code - Must-have extensions for Developers

Visual Studio Code is one of the awesome developer tools by Microsoft. Let’s…

How to Patch and Build Python 3.7.9 for FIPS enabled Openssl

How to Patch and Build Python 3.7.9 for FIPS enabled Openssl

Introduction In this post, we will see Python 3.7.9 patch for FIPS enabled…

How to Fetch JSON of all Videos of a Youtube Channel

How to Fetch JSON of all Videos of a Youtube Channel

Youtube APIs are great way to fetch details about video or channels. I’ve…

Latest Posts

REST API Design: Pagination, Versioning, and Best Practices

REST API Design: Pagination, Versioning, and Best Practices

Every time two systems need to talk, someone has to design the contract between…

Efficient Data Modelling: A Practical Guide for Production Systems

Efficient Data Modelling: A Practical Guide for Production Systems

Most engineers learn data modelling backwards. They draw an ER diagram…

Deep Dive on Caching: From Browser to Database

Deep Dive on Caching: From Browser to Database

“There are only two hard things in Computer Science: cache invalidation and…

System Design Patterns for Real-Time Updates at High Traffic

System Design Patterns for Real-Time Updates at High Traffic

The previous articles in this series covered scaling reads and scaling writes…

System Design Patterns for Scaling Writes

System Design Patterns for Scaling Writes

In the companion article on scaling reads, we covered caching, replicas, and…

System Design Patterns for Managing Long-Running Tasks

System Design Patterns for Managing Long-Running Tasks

Introduction Some operations simply can’t finish in the time a user is willing…