Mastering Git Flow: Commands and Advantages for Effective Version Control Skip to main content

Commands & Advantages

Saurabh Dhariwal

Saurabh Dhariwal

Gitflow

What is Gitflow?

Gitflow is a Git branching model designed for collaborative software development. Vincent Driessen introduced it in a movie, and it has gained popularity for its structured approach. Unlike trunk-based development, Gitflow involves feature branches and multiple primary branches, resulting in a more intricate branching model.

 

In the Gitflow model, developers create feature branches to work on specific features or changes. These feature branches are not immediately merged into the main trunk branch. Instead, they are kept separate until the feature is fully developed and ready for integration. While providing isolation for feature development, this approach may require more collaboration and poses a risk of divergence from the main trunk.

 

Gitflow is particularly suitable for projects with scheduled release cycles and aligns well with the DevOps practice of continuous delivery. It builds upon the concepts of the Feature Branch Workflow, introducing specific roles for different branches and outlining their interactions. Alongside feature branches, Gitflow incorporates branches dedicated to preparing, maintaining, and documenting releases. This workflow retains the advantages of the Feature Branch Workflow, such as pull requests and streamlined collaboration.

GitFlow is a collection of Git commands to provide many repository operations with just single command. It helps to keep track of features, hotfixes and releases in projects. It is used for projects where you might have multiple streams of work running concurrently.

Installing git-flow

+ OSX

  • Homebrew: $ brew install git-flow-avh
  • Macports: $ port install git-flow-avh
     

+ Linux

$ apt-get install git-flow

 

+ Windows (Cygwin)

$ wget -q -O - --no-check-certificate

 

install stable | bash

See the Wiki for detailed Installation Instructions.

Initialization

You need to initialize a new repo inside an existing git repository. Run following command:

git flow init [-d]

 

<p><strong>-d</strong> flag will accept all defaults.</p>

<p>This will ask questions like which branches you would like to use as development and production branches, and how would your prefixes be named. Press Enter to accept default suggestions.<br />
&nbsp;</p>

<h4><strong>FEATURE BRANCHES</strong></h4>

<p>Using git-flow feature branches you can easily work on multiple features of project at the same time.</p>

<p><strong>+ Create a feature branch</strong></p>

<p>New feature branch is created from the 'develop' branch and switches to it.</p>
 

git flow feature start MYFEATURE

 

Gitflow

+ List all feature branches

-   git flow feature

 

+ Publish a feature branch

Push a feature branch to the remote repository.

-   git flow feature publish MYFEATURE

 

Note: This can be used only once in a branch, next time you want to push any code in same feature branch you need to use:

 -   git push origin feature/MYFEATURE

 

+ Track a feature branch

Get a feature published by another user (Pull a feature branch). git flow feature track MYFEATURE

This is similar to:

  • git checkout feature/MYFEATURE
  • Git pull origin feature/MYFEATURE

+ Finish a feature branch

Finish the development of a feature. This action performs the following:

  • Merges MYFEATURE into 'develop'
  • Removes the feature branch
  • Switches back to 'develop' branch
  • git flow feature finish MYFEATURE
Gitflow

VERSIONED RELEASE

Using git-flow release branches you can create tagged and versioned releases. Create a new release branch when you have completed current version and it’s ready to deploy to production.

+ Create a release branch

New release branch is created from the 'develop' branch and switches to it. git flow release start MYRELEASE

Gitflow

+ List all release branches

 -    git flow release

 

<p><strong>+ Publish a release branch</strong></p>

<p>Push a release branch to the remote repository.</p>
 

-     git flow release publish MYRELEASE

 

<p><strong>+ Track a release branch</strong></p>

<p>Get a release published by another user (Pull a release branch).</p>
 

-     git flow release track MYRELEASE

 

+ Track a release branch

Get a release published by another user (Pull a release branch).

-     git flow release track MYRELEASE

 

+ Finish a release branch

Finish the development of a release. This action performs the following:

  • Merges MYRELEASE into ’master’
  • Tags the release with its name
  • Back-merges the release into 'develop'
  • Removes the release branch
git flow release finish MYRELEASE

 

Note: Don't forget to push your tags

git push --tags

 

Gitflow

HOTFIXING PRODUCTION CODE

Using hotfix branches you can act immediately upon an undesired bugs on production version.

+ Create a hotfix branch

New release branch is created from the 'develop' branch and switches to it.

git flow hotfix start MYHOTFIX

 

myhotfix argument marks the new hotfix release name.

Gitflow

+ List all hotfix branches

 -     git flow hotfix

 

+ Finish a hotfix branch

Finish the development of a release. This action performs the following:

  • Merges MYHOTFIX into ’master’ & ‘develop’
  • Tags master merge with the hotfix version.
 -     git flow hotfix finish MYHOTFIX

 

Gitflow

 

    Advantages of Git Flow

  • Gitflow was developed to manage the branching mechanism with a standardised approach when developing features, handling releases and managing hotfixes.
  • Using multiple separate branches in Git will provide flexibility but gets complex. This is easy in gitflow.
  • Gitflow makes developer speed up the process with familiar branch structure.
  • Single command to do multiple things at a time.
  • Switching branches is easy.
  • Keep repository & process clean and tidy.

Feel free to share your views regarding Git Flow we follow strictly for every project to ensure best results and need any assistance for Web Development Service Contact us now!!

Frequently Asked Questions

How does GitFlow make collaboration easier?

GitFlow organizes development into branches, making it simple to collaborate. Features and releases are isolated, minimizing conflicts and ensuring a smoother team collaboration experience.

What is the purpose of the 'develop' branch in GitFlow?

The 'develop' branch in GitFlow serves as a feature staging area. When complete features are merged into 'develop,' keep the 'master' branch reserved for stable releases. This helps maintain a clean and structured development history.

How do I handle hotfixes using GitFlow?

Hotfixes in GitFlow are for quickly addressing issues in the 'master' branch. The command git flow hotfix start initiates a hotfix, and git flow hotfix finish completes it, ensuring that urgent fixes are efficiently managed without disrupting ongoing development.

How does GitFlow help with versioning in my project?

GitFlow simplifies versioning by separating features and releases. Features are developed in feature branches, and when ready, they are merged into 'develop.' Releases are then created from 'develop,' making managing and tracking the project's version history easy.

Can GitFlow be integrated with Git hosting services like GitHub or GitLab?

Yes, GitFlow seamlessly integrates with popular Git hosting services. You can create branches, merge features, and manage releases directly from these platforms, enhancing collaboration and version control.

Is there a simplified way to remember GitFlow commands?

Yes, a helpful mnemonic for common commands is "Start a Feature, Finish a Feature," or "Start a Release, Finish a Release." This simplifies understanding commands like git flow feature start and git flow feature finish.