9. Practical Example: Using GitFlow
Let's walk through a practical example of using GitFlow for a hypothetical project.
Setting up a project with GitFlow
Initialize a new Git repository:
Commit an initial empty commit (this helps in setting up the base for branching):
Create the
develop
branch and switch to it:
Now you have both master
and develop
branches, with develop
being the one you'll work on.
Developing a new feature
Create a new feature branch:
Make changes for the feature and commit them:
Once the feature is complete, merge it into the
develop
branch:
Preparing for a release
Create a release branch:
Make any final adjustments needed for the release (like bumping version numbers, updating documentation, etc.) and commit those changes.
Once the release is ready, merge it into
master
and tag it:Also, merge the changes back into
develop
:Delete the release branch:
Handling hotfixes
Create a hotfix branch from
master
:Make and commit the hotfix changes:
Merge the hotfix branch into both
master
anddevelop
:Delete the hotfix branch:
Merging back to the main branches
Throughout the GitFlow process, you've been merging changes back to the main branches (master
and develop
) at the end of each feature, release, or hotfix. This ensures that:
The
master
branch always reflects the production-ready state.The
develop
branch always contains the latest delivered and approved features.
By consistently merging back, you ensure that both branches are up-to-date and that features, fixes, and releases are systematically integrated into your project's main lines of development.
Last updated