GitFlow Explained

By Simon Baynes

Branching Model

Concepts

master
Represents what is in production
develop
Long running branch that contains latest tested work ready for the next release
feature
This is where work is done. These are discrete branches for doing an atomic feature
release
This is how you release all new completed features in 'develop' that are now ready for production
hotfix
This how you release an emergency fix to production

Working with Features

Creating Features

$ git checkout -b myfeature develop
Switched to a new branch "myfeature"

Finishing a Feature

$ git checkout develop
Switched to branch 'develop'

$ git merge myfeature --no-ff
Updating ea1b82a..05e9557
(Summary of changes)

$ git branch -d myfeature
Deleted branch myfeature (was 05e9557).

$ git push origin develop

No Fastforward Merge

Working with Releases

Releases are there to start the preparation for going live.

Creating a Release

$ git checkout -b release-1.2 develop
Switched to a new branch "release-1.2"

$ ./bump-version.sh 1.2
Files modified successfully, version bumped to 1.2.

$ git commit -a -m "Bumped version number to 1.2"
[release-1.2 74d9424] Bumped version number to 1.2
1 files changed, 1 insertions(+), 1 deletions(-)

Finishing a Release

$ git checkout master
Switched to branch 'master'

$ git merge release-1.2 --no-ff
Merge made by recursive.
(Summary of changes)

$ git tag -a 1.2

$ git checkout develop
Switched to branch 'develop'

$git merge release-1.2 --no-ff
Merge made by recursive.
(Summary of changes)

$ git branch -d release-1.2
Deleted branch myfeature (was 05e9557).

What if you need to fix something in production?

Working with Hotfixes

Creating a Hotfix

$ git checkout -b hotfix-1.2.1 master
Switched to a new branch "hotfix-1.2.1"

$ ./bump-version.sh 1.2.1
Files modified successfully, version bumped to 1.2.1.

$ git commit -a -m "Bumped version number to 1.2.1"
[hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
1 files changed, 1 insertions(+), 1 deletions(-)

Fix the bug

$ git commit -m "Fixed severe production problem"
[hotfix-1.2.1 abbe5d6] Fixed severe production problem
5 files changed, 32 insertions(+), 17 deletions(-)

Finishing a Hotfix

$ git checkout master
Switched to branch 'master'

$ git merge hotfix-1.2.1 --no-ff
Merge made by recursive.
(Summary of changes)

$ git tag -a 1.2.1

$ git checkout develop
Switched to branch 'develop'

$ git merge hotfix-1.2.1 --no-ff
Merge made by recursive.
(Summary of changes)

$ git branch -d hotfix-1.2.1
Deleted branch hotfix-1.2.1 (was abbe5d6).

What if there is an existing Release?

When a release branch currently exists, the hotfix changes need to be merged into that release branch, instead of develop

Any Questions?

References

GitFlow
Vincent Driessen's original post on the subject.
GitFlow Command Line Tools
Command line tools that simplify some of the tasks outlined in this presentation.
Learn Git Branching
You can practice here.