Full Gitflow init workflow example

Gitflow workflow tutorial

If you plan to use the Gitflow workflow in your software development project, the first thing you need to do after Git and Gitflow are installed is run the “git flow init” command.

In this tutorial, we’ll take you through the Gitflow init process and then follow up the repository initialization with a full Gitflow workflow that incorporates master, develop, feature and release branches. If you want to learn Gitflow, from the “init” command right through to pushing a release branch into production, this example is for you.


Change the master and develop branches to main and development. We leave the rest at their defaults.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial
$ git flow init
Initialized empty Git repository in C:/_tools/temp/my-git-flow/.git/
No branches exist yet. Base branches must be created now.
Branch name for production releases: [master] main
Branch name for "next release" development: [develop] development

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? []
Hooks and filters directory? [C:/_tools/temp/my-git-flow/.git/hooks]

Notice there are only two branches after a “git flow init” command.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git branch -a
* development
main

gitflow release branch

The Gitflow release branch is made from the develop branch and gets merged into both master and develop when finished.

This creates a new feature branch named “feature_branch.”

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git flow feature start feature_branch
Switched to a new branch 'feature/feature_branch'

Summary of actions:

  • A new branch “feature/feature_branch” was created, based on “development.”
  • You are now on branch “feature/feature_branch.”

Now, start committing on your feature. When done, use:

git flow feature finish feature_branch

There are now three branches.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ git branch -a
development
* feature/feature_branch
main

Add a file to represent a feature and then do a Git commit.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ touch feature.html

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ ls
feature.html

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ git add .

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ git commit -m "feature complete!"
[feature/feature_branch f2e257f] feature complete!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 feature.html

Just view the commit history.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ git reflog
f2e257f (HEAD -> feature/feature_branch) HEAD@{0}: commit: feature complete!
8fdc0d7 (main, development) HEAD@{1}: checkout: moving from development to feature/feature_branch
8fdc0d7 (main, development) HEAD@{2}: checkout: moving from main to development
8fdc0d7 (main, development) HEAD@{3}: commit (initial): Initial commit

Finish work on the feature branch. This merges and deletes it.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (feature/feature_branch)
$ git flow feature finish feature_branch
Switched to branch 'development'
Updating 8fdc0d7..f2e257f
Fast-forward
feature.html | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 feature.html
Deleted branch feature/feature_branch (was f2e257f).

Summary of actions:

  • – The feature branch “feature/feature_branch” was merged into “development.”
  • – Feature branch “feature/feature_branch” has been locally deleted.
  • – You are now on branch “development.”

Notice how the feature branch is now gone.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git branch -a
* development
main

There are no tags on the repo yet.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git tag -l

Start a “git flow release” branch.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git flow release start '0.1.0'
Switched to a new branch 'release/0.1.0'

Summary of actions:

  • A new branch “release/0.1.0” was created, based on “development.”
  • You are now on branch “release/0.1.0”

Follow-up actions:

  • Bump the version number now!
  • Start committing last-minute fixes in preparing your release.
  • When done, run:
git flow release finish '0.1.0'

We now have three branches.


 
GitFlowInit@Example MINGW64 /c/git-flow-tutorial (release/0.1.0)
$ git branch -a
development
main
* release/0.1.0

Add a file to represent a fix and do a Git commit.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (release/0.1.0)
$ touch release-fix.html

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (release/0.1.0)
$ git add .

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (release/0.1.0)
$ git commit -m "release fixed"
[release/0.1.0 c1f756f] release fixed
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 release-fix.html

Finish the release branch to merge it and delete it.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (release/0.1.0)
$ git flow release finish '0.1.0'
Switched to branch 'main'
Merge made by the 'recursive' strategy.
feature.html | 0
release-fix.html | 0
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 feature.html
create mode 100644 release-fix.html
Already on 'main'
Switched to branch 'development'
Merge made by the 'recursive' strategy.
release-fix.html | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 release-fix.html
Deleted branch release/0.1.0 (was c1f756f).

Summary of actions:

  • Release branch “release/0.1.0” has been merged into “main.”
  • The release was tagged “0.1.0”.
  • Release tag “0.1.0” has been back-merged into “development.”
  • Release branch “release/0.1.0” has been locally deleted.
  • You are now on branch “development.”

Note we are back to two branches.


 
GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git branch -a
* development
main

All of the files have been merged into the development branch.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ ls
feature.html release-fix.html

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (development)
$ git checkout main
Switched to branch 'main'

All of the files have also been merged into the “main/master branch.”

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (main)
$ ls
feature.html release-fix.html

And the merge to master added a Git tag.

GitFlowInit@Example MINGW64 /c/git-flow-tutorial (main)
$ git tag -l
0.1.0

And that completes a full Gitflow workflow, starting with the “git flow init” command and ending with a merge of the release branch into master.

Note that this Gitflow workflow did not include the hotfix branch as shown below. But that one branch aside, this was a fairly complete Gitflow example.

Gitflow Hotfix Branch Diagram

The Gitflow hotfix branch is one part of the larger Gitflow workflow.