Eyes, JAPAN Blog > Simplify Branching Development with git-flow

Simplify Branching Development with git-flow

LyEdward

Introduction


For the first post of the new year, I thought I should take a moment to remind ourselves of some of the basic tools that are available for every software developer to freely use. When you think about software tools that virtually every developer uses, Git might be one of the first things that come to mind. After all, it is the de facto standard for version control software, and many of the websites that host source code repositories as a service (such as GitHub or GitLab) along with the countless number of projects and software hosted on these sites would not be possible without it. I do, however, want to highlight for this post an extension for Git that not everyone might know about (especially newer developers), and that is git-flow.

Why git-flow?


Professional software development is often done using this well-known branching model, where the source code is separated into production, main development, and any number of working development versions, each marked with its own branch. However, the process of adding even a single feature or bugfix, large or small, can be a bit tedious through Git, as most of the steps are largely the same. For example, to develop a new feature from start to finish:

  1. Create a new branch from the development branch, naming it after the desired feature along with a prefix such as “feature/”.
  2. Checkout into this new branch.
  3. Implement the feature and commit the changes.
  4. Once you are done, checkout back to the development branch.
  5. Merge the changes from the feature branch into the development branch.
  6. Finally, delete the feature branch.

For this reason, git-flow was eventually developed in order to simplify and automate the process.

Installation


If you use a GUI client to interface with Git, chances are, it either already comes with git-flow out of the box or can be added/enabled via a plugin. For those who prefer the CLI like me, however, installation is still just a single command away, assuming that it is not bundled with the Git CLI already (as is the case for the Windows version).

For macOS (via Homebrew):

$ brew install git-flow-avh

For Debian and Debian-based Linux distributions (via apt):

$ sudo apt-get install git-flow

For Arch Linux and Arch-based distributions (via the AUR):

$ paru -S gitflow-avh

Basic Usage


For this brief introduction, I will be using the git-flow CLI to illustrate the basic commands. These commands will very likely have some equivalent in the GUI clients that support git-flow, so please refer to the documentation for your client for more details.

To enable git-flow for a Git project (using the default configuration):

$ git flow init -d

To create a new feature branch named “feature/my_feature” and checkout into this branch:

$ git flow feature start my_feature

To merge the feature branch into the development branch and (locally) delete the finished feature branch:

$ git flow feature finish my_feature

Now, with just these two commands, the development loop has been simplified to:

  1. Start a new feature branch, naming it after the desired feature.
  2. Implement the feature and commit the changes.
  3. Finish the feature branch to merge the changes.

You can also create and merge “bugfix”, “release”, and “hotfix” branches using the exact same procedure; simply replace “feature” with the desired keyword in such cases. The only difference between them lies in the underlying implementation (which is again based on the branching model).

Conclusion


For the most part, these are the only commands you will ever need to know in order to use git-flow effectively on a regular basis. Although the commands are very simple, such convenience will surely lead to an increase in productivity and efficiency. as the amount of time saved can be significant over the long run, especially for larger projects. Most importantly, it will allow you to focus more time on your code and not have to worry about things like stale branches or an errant commit tree. I hope every developer will take advantage of this opportunity in order to write not just great code, but great code done quick!

  • このエントリーをはてなブックマークに追加

Comments are closed.