Skip to content
Search

Git flow

lastmod 2025-02-14created 2017-08-3122 edits

A collection of Git extensions to provide high-level repository operations for Vincent Driessen's branching model.

How to install

$ brew install git-flow
## OR:
$ brew install git-flow-avh

Git Branch types (5)

The Gitflow Workflow uses five branches in total: main branches that always exist (master, develop) and supporting branches that exist only for a limited time (feature, release, hotfix).

Master Branch

Branch that can be shipped as a product

Used to manage the release history. That is, it holds only deployable states.

Develop Branch

Branch for developing the next release

Used to merge the branches for feature development. That is, once all features have been added and bugs fixed so that it is in a stable, deployable state, the develop branch is merged into the ‘master’ branch.

Day-to-day development is based on this branch.

Feature Branch

Branch for developing a feature

A feature branch is branched off the ‘develop’ branch whenever a new feature or bug fix is needed. Since work on a feature branch generally does not need to be shared, it is managed in your own local repository.

When development is complete, it is merged into the ‘develop’ branch to share it with others.

Thoughts on feature branches

Feature branching is a source code branching pattern where a developer opens a branch when she starts work on a new feature. She does all the work on the feature on this branch and integrates the changes with the rest of the team when the feature is done.

While she is working, she can merge changes that the rest of the team has checked in into her branch to reduce the integration when the feature is done, but she does not put her changes into the common codebase until then. As a result, two people working on different feature branches do not integrate their work until the second person merges their work into the common codebase.

Feature branching is a popular technique and is particularly well suited to open-source development. By keeping all the work done on a feature away from the team's common codebase until it is complete, it lets you defer all the risk involved in merging until that point. However, this isolation prevents early detection of problems. More seriously, it also discourages refactoring. Without refactoring, the health of the codebase often deteriorates badly.

The consequences of using feature branches depend greatly on how long it takes to complete a feature. Teams that typically complete a feature in a day or two can integrate often enough to avoid the problems of delayed integration. Teams that take weeks or months to complete a feature run into these difficulties much more.

Release Branch

Branch for preparing the current release

Using a dedicated branch for releases lets one team prepare that release while another team continues developing features for the next release. That is, it is great for defining clean-cut development phases.

Hotfix Branch

Branch for fixing bugs found in a released version

A branch created from the ‘master’ branch when a released version needs an urgent fix. Fixing the problem in the ‘develop’ branch to produce a deployable version takes a lot of time and makes stability hard to guarantee, so you branch directly from the immediately deployable ‘master’ branch, fix only what is needed, and then merge it back into the ‘master’ branch and deploy it.

Usage

Initialization
To use gitflow, you must initialize the repository as follows. (if unsure, just keep pressing Enter)

:

$ git flow init

Which branch should be used for bringing forth production releases?
   - develop
   - master
   - release/1.0.0
Branch name for production releases: [master]

Which branch should be used for integration of the "next release"?
   - develop
   - release/1.0.0
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? [] v
Hooks and filters directory? [/Users/user/Project/c2api/.git/hooks]
Start a new feature.

:

$ git flow feature start {FEATURE_NAME}
Finish a feature.

:

$ git flow feature finish {FEATURE_NAME}
Publish a feature (It uses to collaborate with other people).

:

$ git flow feature publish {FEATURE_NAME}
Getting a published feature.

:

$ git flow feature pull origin {FEATURE_NAME}
Getting a help message

:

$ git flow
$ git flow feature help
$ git flow feature delete -h

Creating feature/release/hotfix/support branches

To list/start/finish feature branches

git flow feature
git flow feature start <name> [<base>]
git flow feature finish <name>

For feature branches, the <base> arg must be a commit on develop.

To push/pull a feature branch to the remote repository

git flow feature publish <name>
git flow feature pull <remote> <name>

To list/start/finish release branches

git flow release
git flow release start <release> [<base>]
git flow release finish <release>

For release branches, the <base> arg must be a commit on develop.

To list/start/finish hotfix branches

git flow hotfix
git flow hotfix start <release> [<base>]
git flow hotfix finish <release>

For hotfix branches, the <base> arg must be a commit on master.

To list/start support branches

git flow support
git flow support start <release> <base>

For support branches, the <base> arg must be a commit on master.

Troubleshooting

No such ref was fetched

If the feature/branch you are currently using has been removed from the remote repository, using git pull produces the following error.

$ git pull --all
Fetching origin
Your configuration specifies to merge with the ref 'refs/heads/feature/rmtask'
from the remote, but no such ref was fetched.

In this case, if you want to keep the same branches as the repository, use the git flow feature delete command.

$ git flow feature delete -f rmtask
Deleted branch feature/rmtask (was c2e8c9c).

Summary of actions:
- Feature branch 'feature/rmtask' has been deleted.
- You are now on branch 'develop'

Then clean up the remaining remote branches with the command below.

$ git remote prune origin

Flows

See also

Favorite site

author Zer0 sitemap