<!-- JSON-LD markup generated by Google Structured Data Markup Helper. --><script type="application/ld+json">{  "@context" : "http://schema.org",  "@type" : "Article",  "name" : "Git Branching Strategies",  "author" : {    "@type" : "Person",    "name" : "Subham Majavadiya"  },  "articleSection" : "Git Branching Strategies",  "articleBody" : [ "Master branch", "Integration branch", "Staging branch", "Dev-deploy branch", "Feature deployment", "Bugfix deployment" ],  "url" : "https://www.engati.com/blog/git-branching-strategies",  "publisher" : {    "@type" : "Organization",    "name" : "Engati"  }}</script>

Tech Corner

Git Branching Strategies

Jul 20
3-4 mins

Table of contents

Key takeawaysCollaboration platforms are essential to the new way of workingEmployees prefer engati over emailEmployees play a growing part in software purchasing decisionsThe future of work is collaborativeMethodology

In one of the products we've worked on, we used ‘git’ for version controlling with GitLab as our hosting provider. In this article, we're going to discuss hands-on on git as well as the git branching strategies we follow. Along with recommendations on how to use git to accomplish work in a consistent and productive manner.

Git commands

To create a copy of a git repository from the remote source to your local also set the remote to the original source so that you can pull/push on the same repository.

git clone <remote origin="" url=""></remote>

To create a new branch from an existing branch with preserve the uncommitted/stash changes.

git checkout -b <branch_name></branch_name>

To check all the branch's revisions in your local system also helps in finding out which branch is currently active.

git branch

To add content from the working directory into the staging area (or “index”) for the next, commit.

git add -p

Create a new commit containing the current contents of the index and the given log message describing the changes

git commit -m <commit message=""></commit>

To publish locally committed changes to origin.

git push origin <branch name=""></branch>

To fetch & merge changes from origin to your local branch.

git pull origin <branch name=""></branch>

To record the current state of the working directory and the index, but want to go back to a clean working directory.

git stash

To list all the recorded index of the working directory/repository.

git stash list

It does the same but leaves it in the stash stack.

git stash pop

To apply the top stashed element to your current working branch/directory and remove it from the stack

git stash apply

To view commit history with SHA for current active branch

git log

To reset the active branch head to a particular commit or branch.

git reset — hard <commit sha="" branch="" name=""></commit>

Git Branching Strategies

Master branch

This is the main branch of the repository in which we have the latest stable code of production.

General rules:

- Access to direct merge is restricted

- Best practice is to create a CI/CD pipeline to merge code into this branch after deployment is done in Production

- It should always have the latest stable version of production server

- Allow access to only CD tools lke Jenkins to make commits to this branch

The master branch should never have unreleased code, i.e., commits made but not yet released).

Integration branch

This is the most important and active branch of the repository from which we make releases to the production server.

General rules:

- Access to direct merge is restricted

- Code is merged into this branch when it becomes eligible for production deployment

- Code in this branch should always be in a deployable state to production

- QA tested code should be into this branch using CI/CD tools

Ideally, the Integration branch should also never have unreleased code, some time on the deployment day when the code is merged a few hours before deployment time.

Staging branch

This is another stable branch of the repository for QA-environment from which we make releases to the QA server.

General rules:

-Access is restricted

-Changes can be submitted only through Pull Requests. No direct commits are allowed

-Should always have the latest stable/released version of QA release server

-It is absolutely necessary to ensure only dev tested and reiviewed code gets merged into this branch

Prior to production deployment, all the feature changes must get merged in staging and validated on QA. Once validation is completed, we'll raise another MR towards the integration branch.

Dev-deploy branch

This branch will be used primarily for deploying on-going development work to the Dev environment. Since multiple teams may work on different features, projects and bugs at the same time, all of them need a Dev environment to test the changes before moving to QA. The idea of the Dev-deploy branch is to merge multiple feature branches to a common branch and deploy the same.

This is so that everyone can use a shared development environment at the same time to validate changes.

Dev- deploy strategy

Feature deployment

Branching process for feature deployment

Bugfix deployment

Branching process for bug fix deployment

Do’s and Don’ts


DO's for Git Branching Strategies
Don'ts for Git Branching Strategies

To sum it up

We hope this article will helps you use git in a more productive manner. Another tool that boosts productivity are chatbots. Get started with an Engati Chatbot today!


Andy is the Co-Founder and CIO of SwissCognitive - The Global AI Hub. He’s also the President of the Swiss IT Leadership Forum.

Andy is a digital enterprise leader and is transforming business strategies keeping the best interests of shareholders, customers, and employees in mind.

Follow him for your daily dose of AI news and thoughts on using AI to improve your business.

Catch our interview with Andy on AI in daily life

Continue Reading