DEV Community

Riccardo Solazzi
Riccardo Solazzi

Posted on • Originally published at thezal.dev

GitFlow and GitKraken: Streamlining Your Version Control Workflow!

Hello there, TheZal here! Today, we're going to talk about something that's a game-changer in the Git world – GitFlow! If you've ever found yourself lost in a sea of branches, struggling to keep track of changes, GitFlow is here to save the day.

Hello There!

What the f...low?

What is GitFlow?

Gitflow is a popular branching model that provides a structured approach to managing Git repositories. It was introduced by Vincent Driessen as a set of guidelines to facilitate collaboration and streamline the development process. At its core, Gitflow defines specific branches for different purposes, making it easier for developers to work in a coordinated manner.

The main branches in Gitflow are:

Master: This branch represents the production-ready code, and it should always contain the stable version of the project.

Develop: The develop branch is where ongoing development takes place. It serves as the integration branch for all the features and bug fixes.

Feature branches: Developers create feature branches off the develop branch to work on new features. Once complete, these branches are merged back into develop.

Release branches: When the development on the develop branch is ready for release, a release branch is created. Any final tweaks and testing happen here before merging into master and develop.

Hotfix branches: If a critical issue arises in the production code, a hotfix branch is created from master to fix the problem. The changes are then merged back into both master and develop.

But what's the real gain?

Chding! Money!

Gitflow brings several benefits to the development process, making it a preferred workflow for many teams:

  • Clear Structure: The defined branches give a clear structure to the repository, making it easier to understand the state of the project at any given time.

  • Parallel Development: Gitflow allows developers to work on multiple features simultaneously without affecting the main codebase.

  • Stability and Reliability: By keeping the master branch stable at all times, you ensure that production releases are reliable and free from experimental or unfinished code.

  • Easy Collaboration: Developers can collaborate effectively by following a set of rules and guidelines. The process of merging and reviewing code becomes smoother.

  • Hotfix Deployment: The hotfix branches enable swift bug fixes in production, preventing any prolonged downtime.

Believe the Flow!

Believe the Flow!

For Gitflow to be effective, it's essential to adhere to some best practices:

  • Commit Often: Frequent commits in feature branches make it easier to track changes and isolate potential issues.

  • Code Reviews: Encourage thorough code reviews before merging any branches. This helps maintain code quality and reduces the likelihood of introducing bugs.

  • Continuous Integration: Implement a robust CI/CD pipeline to automatically build, test, and deploy changes. This ensures that the code is always in a releasable state.

  • Versioning: Consider adopting semantic versioning to make it clear what each release contains in terms of new features, bug fixes, or breaking changes.

  • Avoid Direct Commits to Master and Develop: All code changes should go through the appropriate branch, even for urgent bug fixes.

To Merge or not To Merge To Rebase?

Shakespeare's Hamlet

Two common Git commands for integrating changes from one branch into another are git merge and git rebase.

  • Git Merge: When you merge a branch into another, Git combines the changes and creates a new commit on the target branch. This preserves the commit history of both branches but can result in a more cluttered history, especially when dealing with multiple feature branches.

  • Git Rebase: Rebase, on the other hand, moves the entire feature branch to a new base commit. It essentially replays the changes on top of the target branch, resulting in a linear commit history. This makes the history cleaner and easier to follow but can lead to conflicts that need to be resolved before completing the rebase.

So when should you use one over the other?

  • Git Merge: Use merge when you want to preserve the complete history of a feature branch and when you're collaborating with multiple developers on the same branch. Merge also works well for incorporating changes from long-lived branches like master or develop.

  • Git Rebase: Use rebase when you want a cleaner and more linear commit history. Rebase is suitable for short-lived feature branches that are still under development and need to be kept up-to-date with the latest changes from the parent branch.

It's important to note that while rebasing can offer a cleaner history, it should be used cautiously and not on shared branches, as it rewrites the commit history and can lead to conflicts for other team members.

The Kraken inside the Flow!

Krakenize the flow!

GitKraken is a popular Git client that provides an intuitive and user-friendly interface for working with Git repositories, including support for Gitflow. Here's how you can leverage GitKraken to implement Gitflow effectively:

Initializing Gitflow

First initialize Gitflow in Preferences -> Gitflow and change the default branch names if desired.

Gitflow Preferences

Once you set things up, you'll always find two branches: "master," which is the one we use in production, and "develop," the version we're currently working on for the next release.

Any changes we make are merged into these branches. If you don't already have these branches in your local repository, don't worry! GitKraken Client will create them for you when Gitflow is set up.

Usage

Once you've got Gitflow set up in your repository, you'll notice an extra menu on the left panel. From there, you can easily start or finish any of your Gitflow branches.

If you want to create a new Gitflow branch, just hit the green button on the Gitflow menu to the left.

Gitflow Menu

When you're adding a branch, make sure to include the prefix for the Gitflow branch type, like "feature/branch-name" for example. If you forget to add the prefix, the branch will still show up in the local repository section, but it won't appear in the Gitflow menu. So, it's essential to follow the naming convention to manage your branches effectively.

Gitflow Start Branch

Feature Branches

Feature branches are handy for working on new features or fixing bugs. They are usually kept within your local repository and not shared with others until they are ready.

When you finish working on a feature branch, GitKraken Client will take care of merging it into the "develop" branch and remove the feature branch from your local repository, so you don't have to worry about that.

Gitflow Feature Branch

Additionally, you can choose to rebase the feature branch on top of the "develop" branch if you prefer that approach for integrating changes.

Release Branches

Releases represent significant updates or improvements to your product, and they come in major and minor versions. These versions are usually shared with other collaborators who are also working on the same release.

Once a release is ready to go, when you finish it, GitKraken Client will handle the process of merging the release branch into both the "master" and "develop" branches. This action also creates a tag with the release name, which is useful for future reference and version tracking.

Gitflow Release Branch

Hotfix Branches

Hotfixes in Gitflow are similar to Releases, but with one key difference: hotfix branches are created on top of the "master" branch, while release branches are created on top of the "develop" branch.

Hotfixes are designed for swiftly deploying critical changes to the production branch. They are commonly used for fixing typos, addressing urgent bugs, and making quick updates that need to be pushed out to production as soon as possible.

Once a hotfix is ready, GitKraken Client takes care of merging the changes into both the "master" and "develop" branches, ensuring that the fix is incorporated into both the production and ongoing development codebases. This helps maintain consistency and keeps the codebase up to date with the latest changes.

Gitflow Hotfix Branch

Tag

Tags serve as markers in a repository's history and are often used to signify specific releases.

Creating tags can be done either through the Gitflow menu or using the command line. When you create a tag from the Gitflow menu in GitKraken Client, it will automatically use the same name as the branch you are tagging. For instance, if you create a tag from a "release/1.0.0" branch, the tag will be named "1.0.0." Moreover, you have the option to include a tag message when finishing a branch, and this message will be attached to the tag.

Gitflow Tag

In the GitKraken Client's Preferences under the Gitflow settings, you can set a tag prefix. When you create a tag from the Gitflow menu, the specified prefix will be added to the tag name. For instance, if you set the tag prefix as "v," and you create a tag from a "release/1.0.0" branch, GitKraken Client will create a tag named "v1.0.0." This allows for better organization and distinction between regular branch names and tag names.

Gitflow Tag

Conclusions

Conclusions

In conclusion, let's break the bad habits combining GitKraken and GitFlow!

Gitflow offers a structured and efficient workflow for collaborative software development, by defining specific branches for different purposes and following best practices, teams can work harmoniously and deliver reliable, stable code. The choice between Git merge and Git rebase depends on the desired commit history and the nature of the feature branches.

With the help of tools like GitKraken, implementing Gitflow becomes even more manageable, as the client streamlines the process and provides an intuitive interface for all team members.

So, embrace the Gitflow, unleash the Kraken, and take your development workflow to new heights! Happy coding!

If you found this useful feel free to leave a comment here or to reach me on Twitter, GitHub, or mail and share it with your dev friends!

Top comments (0)