Git

The Best Git Branching Strategy

1. Introduction

This is an in-depth article related to the Best Git Branching Strategy. Git was developed by Vincent Driessen in 2010. Git typically has two branches in its repositories like master and develop. The development branches can be feature-specific, hot fix specific, release specific, and trunk.

2. Git Branching Strategy

A typical Git branching strategy depends on the stage of the development lifecycle, and release plan. Developers can have their own branches for development. Features are developed during the sprint in the releases. Branches are created for different features.

2.1 Prerequisites

Java 7 or 8 is required on the Linux, windows or mac operating system. Maven 3.6.1 is required for building this application.  A Github account is required.

2.2 Download

You can download Java 8 can be downloaded from the Oracle web site . Apache Maven 3.6.1 can be downloaded from Apache site. Github can be accessed at this link. Gitkraken can be downloaded from this site. Git can be downloaded from this link.

2.3 Setup

You can create an account on GitHub account using the link. You can create a GitHub repository with a Calculator application java code. You can add the file manually to get started. The code is shown below :

Calculator

package org.build.maventool;

/**
 *  Calculator class
 */
public class Calculator
{
   /**
    * getProduct
    * @param val1 integer
    * @param val2 integer
    * @return product of val1 and val2
    */
   public int getProduct(int val1, int val2)
    {
		   return val1*val2;
    }
   
   /**
    * main method
    * @param args arguments
    */
   public static void main(String[] args)
   {
        Calculator calc = new Calculator();
       
        int product = calc.getProduct(43,4);
       
        System.out.println("Product of " + " 43 and 4 is "+product);
   }
}


You can use the below maven pom for building this file.

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>maven-hello</groupId>
    <artifactId>Maven-project</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>Maven-project</name>
    <url>http://maven.apache.org</url>

    <properties>
        
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.11</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.0</version>
                <executions>

                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>org.build.maventool.Calculator</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>


2.4 Why do we need a git Flow Branch Strategy?

In git main branch is the main (master in initial versions of git). The main branch has the production-ready release. The main branch is created first. Development branches are created till the development release completes the test stage. This code is pre-production and deployed in the acceptance stage for acceptance testing. Once the testing is complete, this branch is merged into main through pull requests. New features will be coming out of the development release branches. On the main, tags can be created for different releases. After production, you can have branches specific to release and hotfix. During development, feature-specific branches are created. Feature branches are merged into the development release through a pull request. The pull request is reviewed for merge approval. A release branch is for production release preparation. Defects found on testing will be resolved on the release branch before merging into the main branch. Hotfix branch is used for handling important fixes or patches to the releases. They are merged into the main and tags can be created for hotfixes.

2.5 Git Flow: advantages and disadvantages

The advantages of the git-flow are related to having a clear picture of the project lifecycle in code. Branch names help in showing the features, releases, and fixes being applied. The disadvantages are more in the readability of the history. CI/CD tools need to be run on different configurations for release and development builds. Versions of the product are challenging when you have a multi-tenant application on SAAS.

2.6 What is GitKraken?

Gitkraken is a git client used on different operating systems like Linux, Mac, and Windows. Git commands are modeled as UI actions which are drag and drop style. GitKraken can be integrated with Github and GitHub enterprises. Merge conflicts can be resolved in the user interface. Workflows can be automated with Git actions.

2.7 Git Flow with GitKraken

GitKraken can be used if you are new to Git for quick deployment and code development. You can productive and efficient by using Gitkraken tools for git workflows. GitKraken GUI helps in managing the repositories. The risk comes down in the resolution of conflicts and undoes feature helps in getting things back to the previous state. Merge tool is provided in the Gitkraken application for resolving conflicts. You can also see the diffs using this tool between different branches. Gitkraken is cross-platform and makes Gitflow possible for code development.

2.8 Why do we need a GitHub Flow Branch Strategy?

Github is available for trying out open source development using git on the internet. You can create an account and start creating your own repositories. Github was developed in 2011. It is based on six important principles.

  1. Main branch is production ready to deploy
  2. To develop the application first, create a branch off from main and given a meaningful name
  3. You can commit to that branch locally and regularly push the code to the branch.
  4. For code reviews, you can create a pull request on the branch for merging.
  5. After the code review is completed, you can do the merge into the main branch.
  6. Once it is merged and pushed to the main, it is ready for deployment

Branching strategy is important for open source as there will be multiple users/developers participating in the open-source development. Each developer will be working on the feature and will have his own branch.

2.9 GitHub Flow: advantages and disadvantages

The advantages of GitHub flow are related to the CI/CD. For multiple clients deployment, CI/CD can use different configurations for deployment. The disadvantages are related to the manageability of the releases if the issues are not resolved in time or the release planning is not done properly. Multitenant code versions can be challenging to maintain if the releases are happening in parallel and planning is not proper.

3. Download the Source Code

Download
You can download the full source code of this example here: The Best Git Branching Strategy

Bhagvan Kommadi

Bhagvan Kommadi is the Founder of Architect Corner & has around 20 years’ experience in the industry, ranging from large scale enterprise development to helping incubate software product start-ups. He has done Masters in Industrial Systems Engineering at Georgia Institute of Technology (1997) and Bachelors in Aerospace Engineering from Indian Institute of Technology, Madras (1993). He is member of IFX forum,Oracle JCP and participant in Java Community Process. He founded Quantica Computacao, the first quantum computing startup in India. Markets and Markets have positioned Quantica Computacao in ‘Emerging Companies’ section of Quantum Computing quadrants. Bhagvan has engineered and developed simulators and tools in the area of quantum technology using IBM Q, Microsoft Q# and Google QScript. He has reviewed the Manning book titled : "Machine Learning with TensorFlow”. He is also the author of Packt Publishing book - "Hands-On Data Structures and Algorithms with Go".He is member of IFX forum,Oracle JCP and participant in Java Community Process. He is member of the MIT Technology Review Global Panel.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button