GitFlow - Getting Started

September 2, 2023

GitFlow - Getting Started Hero

GitFlow is a branching model for Git, created by Vincent Driessen. It’s a consistent way to manage and track features, releases, and hotfixes in your projects. This model uses multiple branches to manage the development process efficiently and ensure that you can release your software at any point.

Setting Up GitFlow

To set up GitFlow in your project, you’ll need to initialize your repository with two main branches: main and develop.

# Initialize a new Git repository
git init

# Create the 'develop' branch
git checkout -b develop

# Push the 'develop' branch to the remote repository
git push -u origin develop

The main branch stores the official release history, while the develop branch serves as an integration branch for features.

Working with GitFlow

Feature Branches

Feature branches are used to develop new features for the upcoming or a distant future release. When starting development of a feature, the target release in which this feature will be incorporated may well be unknown. The essence of a feature branch is that it exists as long as the feature is in development, but will eventually be merged back into develop (to definitely add the new feature to the upcoming release) or discarded (in case of a disappointing experiment).

# Start a new feature branch
git checkout -b feature_branch

# Edit some files
git commit -a -m "Start a feature"

# Edit some files
git commit -a -m "Finish a feature"

# Merge back into develop when done
git checkout develop
git merge --no-ff feature_branch

Release Branches

Release branches support preparation of a new production release. They allow for minor bug fixes and preparing meta-data for a release (version number, build dates, etc.). By doing all of this work on a release branch, the develop branch is cleared to receive features for the next big release.

# Start a release branch
git checkout -b release/0.1.0 develop

# Edit some files
git commit -a -m "Bumped version number to 0.1.0"

# Finish up the release branch
git checkout main
git merge --no-ff release/0.1.0

Hotfix Branches

Hotfix branches are very much like release branches in that they are also meant to prepare for a new production release, albeit unplanned. They arise from the necessity to act immediately upon an undesired state of a live production version.

# Start a hotfix branch
git checkout -b hotfix_branch main

# Edit some files
git commit -a -m "Fix something"

# Merge back into main when done
git checkout main
git merge --no-ff hotfix_branch

# Also merge back into develop so it has the fix too!
git checkout develop
git merge --no-ff hotfix_branch

Advanced Topics

GitFlow Extensions

GitFlow Extensions are a set of Git extensions to provide high-level repository operations for Vincent Driessen’s branching model. They add a new command, “flow”, which has several subcommands that encapsulate the workflow.

Download and Installation

GitFlow Extensions can be downloaded from the following sources:

  • For general use, you can download it from the official GitHub repository.
  • For Windows users, you can find instructions on how to install GitFlow on Stack Overflow.
  • For Visual Studio 2022 users, there’s a dedicated GitFlow extension available.
  • Git Extensions, another standalone UI tool for managing Git repositories, can be downloaded from their official website.

How to Use GitFlow Extensions

After installing GitFlow, you can use it in your project by executing git flow init. This command is an extension of the default git init command and doesn’t change anything in your repository other than creating branches for you.

Here’s an example of how to use the GitFlow extensions:

# Start a new feature branch
git flow feature start feature_branch

# Edit some files
git commit -a -m "Start a feature"

# Edit some files
git commit -a -m "Finish a feature"

# Finish the feature branch
git flow feature finish feature_branch

Tips and Tricks

  • The git flow init command is an actual command line tool that has an installation process. The installation process for git-flow is straightforward. Packages for git-flow are available on multiple operating systems.
  • For those who use the Bash or ZSH shell, please check out the excellent work on the git-flow-completion project by bobthecow. It offers tab-completion for all git-flow subcommands and branch names.
  • If you’re using Visual Studio Code, there’s a Git Flow extension available in the marketplace that integrates Git Flow directly into your editor.
  • You can find more detailed tutorials and screencasts on how to use a scalable Git branching model called git-flow on Jeff Kreeftmeijer’s blog post.
  • Remember to export PATH=pwd:$PATH from within the gitflow directory to make sure you’re using the version of gitflow you’re currently developing.

Remember, practice makes perfect. The more you use GitFlow and its extensions, the more comfortable and efficient you’ll become with it.

Final Thoughts

The GitFlow branching strategy is an efficient way to manage and track changes in your projects. It allows you to isolate new features, prepare for releases, and fix bugs in your live application without disrupting the main development flow. By using this model, you can ensure that you’re always ready to release your software at any time.

So what are you waiting for? Get out there an change the world!

If you want to explore your options, please reach out to our team by via email at support@skratsch.com or by calling 1.313.284.5656

Tags: gitgitflowbranching

Steve Kaschimer

Steve Kaschimer

Editor

Steve is a Software and Cloud Engineer, Content Creator, and Innovation Enthusiast. He is open to collaborating on projects that match his skills, which include .NET Framework/Core, C#, APIs, RESTful Services, SQL Databases, and Azure.