Chuck's Academy

Git Branching and Merging

Git Flow and Other Workflow Models

Git Flow and Other Workflow Models

Workflow in Git is crucial to ensure effective and organized collaboration within a development team. This chapter will analyze the Git Flow model, as well as other popular workflow models in Git.

Git Flow

Git Flow is a set of rules and arrangements that structure and organize branching and merging in Git repositories. It was proposed by Vincent Driessen and is popular in projects that follow a version-based release cycle.

Features of Git Flow:

  • Permanent Branches:
    • main: Contains production code.
    • develop: Contains the code for the next version, developed and tested.
  • Support Branches:
    • feature/: Used to develop new features.
    • release/: Prepares a new version.
    • hotfix/: Fixes production bugs.

Installing Git Flow:

To use Git Flow, first install it:

bash

Initializing Git Flow:

To initialize Git Flow in your repository:

bash

The initialization wizard will prompt you to configure the branch names. You can simply press "Enter" to accept the default names.

mobile-image: image-showing-initial-git-flow-setup

Workflow with Git Flow:

  1. Create a Feature Branch:

    bash
  2. Finish a Feature Branch:

    bash
  3. Create a Release Branch:

    bash
  4. Finish and Publish a Release Branch:

    bash
  5. Create a Hotfix Branch:

    bash
  6. Finish a Hotfix Branch:

    bash

Other Workflow Models in Git

GitHub Flow

GitHub Flow is a simple and effective workflow model that works well for continuous deployment and continuous delivery. It provides a lighter structure compared to Git Flow.

Features of GitHub Flow:

  • Only uses the main branch and feature branches.
  • Each new feature is developed in a separate branch derived from main.
  • Feature branches are merged into main through Pull Requests.

Workflow with GitHub Flow:

  1. Create a Feature Branch:

    bash
  2. Work on the Feature and Commit:

    bash
  3. Push the Branch to the Remote Repository:

    bash
  4. Create a Pull Request (PR):

    • Make a PR from the GitHub site from the feature branch to main.
  5. Review and Merge the Pull Request:

    • Once approved, merge the PR to main.

desktop-image: image-showing-github-flow-workflow

GitLab Flow

GitLab Flow combines ideas from both GitHub Flow and Git Flow. It is flexible and can adapt to different development and deployment scenarios.

Features of GitLab Flow:

  • Uses main branches such as main, staging, and production.
  • Supports version and feature branches.
  • Strong emphasis on deployment and production environments.

Workflow with GitLab Flow:

  1. Create a Feature Branch:

    bash
  2. Develop and Commit:

    bash
  3. Push the Feature Branch:

    bash
  4. Create a Merge Request (MR):

    • Make an MR in GitLab from the feature branch to main or staging.
  5. Review and Approval:

    • Review and approve the MR in GitLab.
  6. Deployment:

    • Merge to main or production depending on the workflow configuration.

Comparison of Models

  1. Git Flow: Best for projects with regular releases and a more structured development cycle.
  2. GitHub Flow: Ideal for continuous deployment and projects requiring an agile and lightweight approach.
  3. GitLab Flow: Offers a versatile and robust combination, suitable for different environments and deployment strategies.

Summary

  • Git Flow: Structured with permanent and support branches; useful for traditional release cycles.
  • GitHub Flow: Simple and agile; focused on continuous deployment.
  • GitLab Flow: Flexible and robust; combines advantages of both for different development and deployment strategies.

Choosing the right model for your team will depend on factors such as project complexity, release cycle, and collaboration preferences. In the next chapter, we will see some best practices for Branching and Merging in Git.


Ask me anything