Tutorial 4 · intermediate · 18 min

The Gitflow workflow, step by step

Run a full Gitflow cycle (feature, release and hotfix) with plain Git commands and with the git-flow extension.

Updated

Gitflow uses two long-lived branches and three kinds of short-lived ones. New to the model? Read What is Gitflow? first.

Branch Lives Branches from Merges into
main forever — —
develop forever main —
feature/* days develop develop
release/* days develop main and develop
hotfix/* hours main main and develop

Setup

git switch -c develop main
git push -u origin develop

1. Build a feature

git switch -c feature/login develop
# ...commit work...
git switch develop
git merge --no-ff feature/login
git branch -d feature/login
git push origin develop

In practice the merge usually happens through a pull request whose target is develop.

2. Cut a release

When develop has everything for the next version:

git switch -c release/1.1.0 develop
# bump version numbers, update the changelog, fix release-only bugs
git commit -am "Bump version to 1.1.0"

Only bug fixes go into a release branch, never new features. Meanwhile, work for the next release keeps landing on develop.

Finish it:

git switch main
git merge --no-ff release/1.1.0
git tag -a v1.1.0 -m "Release 1.1.0"

git switch develop
git merge --no-ff release/1.1.0    # bring release fixes back

git branch -d release/1.1.0
git push origin main develop --tags

3. Ship a hotfix

Production is broken and develop contains unfinished work, so branch from main:

git switch -c hotfix/1.1.1 main
# fix, then bump the version
git commit -am "Fix crash on empty cart"

git switch main
git merge --no-ff hotfix/1.1.1
git tag -a v1.1.1 -m "Hotfix 1.1.1"

git switch develop
git merge --no-ff hotfix/1.1.1

git branch -d hotfix/1.1.1
git push origin main develop --tags

If a release/* branch exists right now, merge the hotfix into it instead of into develop. The fix will reach develop when the release finishes.

The git-flow extension

The git-flow command-line extension wraps all of the above. Install the maintained fork (git-flow AVH, or the newer git-flow-next) with your package manager, e.g. brew install git-flow-avh, then:

git flow init -d                  # accept default branch names

git flow feature start login
git flow feature finish login

git flow release start 1.1.0
git flow release finish 1.1.0     # merges to main + develop, tags

git flow hotfix start 1.1.1
git flow hotfix finish 1.1.1

It’s handy, but learn the plain commands first so you understand what it does for you.

Is Gitflow right for you?

Gitflow fits software with explicit, versioned releases: mobile apps, desktop software, libraries, on-prem products. If you deploy a web app many times a day, a simpler model is usually better. See Compare workflows.

One Git tip a week

Short, practical, no spam. Get the free printable Gitflow cheat sheet when you join.

Newsletter launching soon.