Skip to main content

Git Flow

Git Flow is a workflow methodology that facilitates the organization and management of software development in collaborative projects. This methodology is based on the structured use of branches to manage different types of changes and versions of the software, providing a clear strategy for the development and release of functionalities, bug fixes and final versions.

Installing Git Flow

To use Git Flow, you must first install the tool. Depending on your operating system, you can follow the steps below:

  • Linux (Debian/Ubuntu):

    sudo apt-get install git-flow
  • **macOS (using Homebrew):

    brew install git-flow
  • Windows: You can use Git for Windows which includes support for Git Flow, or use tools like scoop:

    scoop install git-flow

Using Git Flow

Once the tool is installed, you can initialize Git Flow in your repository by running:

git flow init

This command will set up the basic branch structure (main, develop, etc.) and prompt you for some initial settings, such as the name of the branches.

Branches in Git Flow

Git Flow defines a set of branches with specific roles that help keep the project organized:

  • main: This is the main branch that always contains the stable code ready to be released to production. It represents the current state of the software in production.

  • develop: This branch serves as the basis for development. It contains code that is in preparation for the next stable release. When it is decided to release a new version, the develop branch is merged with the main branch.

  • **Feature branches (or feature) are used to develop new functionalities. These branches start from develop and, once completed, merge back to develop.

    • Example with Git Flow: To create a new feature branch, you can use the following command:

      git flow feature start nueva_funcionalidad

      When the new functionality is ready, you can finalize it using:

      git flow feature finish nueva_funcionalidad

      This will merge the feature branch with develop and delete it.

  • release branches (release) are created when the code in develop is ready to be released and a version needs to be prepared.

    • Example with Git Flow: To create a release branch for version 1.0, we use:

      git flow release start 1.0

      After you have made the necessary adjustments and are ready to launch, you can finalize the launch branch with:

      git flow release finish 1.0

      This will merge the branch with main and develop, and tag the version in main.

  • Hotfix: Hotfix branches are used to fix critical problems that occur in production.

    • Example with Git Flow: To create a quick fix branch, use:

      git flow hotfix start correccion_critica

      Once you have solved the problem, you can end the quick fix with:

      git flow hotfix finish correccion_critica

      This will merge the branch with main and develop, and tag the version in main.

Workflow

  1. Initialize Git Flow: Set up the basic structure of the project with git flow init.
  2. Development of new features: Feature branches are created to work on new features without affecting the code base.
  3. Release preparation: When the development is ready, a release branch (release) is created for testing and final adjustments before going into production.
  4. Release to production: The release branch is merged with main and tagged with the corresponding version number.
  5. Critical bug fixes: In case of urgent problems, a hotfix branch is created to fix them quickly and the main and develop branches are updated.

Git Flow provides a clear structure for software development, facilitating collaborative work, continuous integration and stable software delivery. This methodology is particularly useful in projects where it is necessary to maintain a clear release cycle and manage multiple releases in parallel.

For more information about Git Flow and how to implement it in your projects, you can consult the Git Flow reference sheet or explore tools such as git-flow, which automate branch management according to this methodology.