Git Flow - Commands & Advantages

Gitflow

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

 

https://raw.github.com/petervanderdoes/gitflow-avh/develop/contrib/gitflow-installer.sh 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]

 

-d flag will accept all defaults.

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.
 

FEATURE BRANCHES

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

+ Create a feature branch

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

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

 

+ Publish a release branch

Push a release branch to the remote repository.

-     git flow release publish MYRELEASE

 

+ Track a release branch

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

-     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!!