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.

<span style="color: #999999"><span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span>



<span style="color: #003366">$ git flow init</span>



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]</span>

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

<span style="color: #999999"><span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git branch -a</span>



<span style="color: #ff0000">*</span> development



main







</span>
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.”

<span style="color: #999999"><span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git flow feature start feature_branch</span>



Switched to a new branch 'feature/feature_branch'</span>

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.

<span style="color: #999999"><span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ git branch -a</span>



development



<span style="color: #ff0000">*</span> feature/feature_branch



main



</span>

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

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ touch feature.html</span>







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ ls</span>



feature.html







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ git add .</span>







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ git commit -m "feature complete!"</span>



[feature/feature_branch f2e257f] feature complete!



1 file changed, 0 insertions(+), 0 deletions(-)



create mode 100644 feature.html

Just view the commit history.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ git reflog</span>



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.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (feature/feature_branch)



<span style="color: #003366">$ git flow feature finish feature_branch</span>



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.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git branch -a</span>



<span style="color: #ff0000">*</span> development



main

There are no tags on the repo yet.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git tag -l</span>

Start a “git flow release” branch.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git flow release start '0.1.0'</span>



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.







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (release/0.1.0)



<span style="color: #003366">$ git branch -a</span>



development



main



<span style="color: #ff0000">*</span> release/0.1.0

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

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (release/0.1.0)



<span style="color: #003366">$ touch release-fix.html</span>







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (release/0.1.0)



<span style="color: #003366">$ git add .</span>







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (release/0.1.0)



<span style="color: #003366">$ git commit -m "release fixed"</span>



[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.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (release/0.1.0)



<span style="color: #003366">$ git flow release finish '0.1.0'</span>



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.







<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (development)



<span style="color: #003366">$ git branch -a</span>



<span style="color: #ff0000">*</span> 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.

<span style="color: #339966">GitFlowInit@Example</span> <span style="color: #800080">MINGW64</span> <span style="color: #ff6600">/c/git-flow-tutorial</span> (main)



<span style="color: #003366">$ git tag -l</span>



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.