Computer scienceSystem administration and DevOpsGitGitflow

Introduction to Gitflow

4 minutes read

You already know what branches are, what they are for, and how to create them. It probably won't surprise you that there are many approaches and techniques for working with branching. We will analyze one of the most famous methods called Gitflow. It is usually used for teamwork on a project, especially if there is a clear release deadline. However, you can study it now, even if you are still working alone. This will be a good start for the future when you join the development team.

Gitflow Structure

The whole gitflow structure boils down to two main branches: main and develop. The main branch is created automatically after you initialized the gitflow repository. In parallel, you also should create a develop branch. In the main, you will keep the source code in a production-ready state to any arbitrary point in time. And in develop, you are to store code containing the most recent published changes. When you are sure that the code in develop branch is finished, you should merge all changes into main . That is, you have some initial version of the project stored in the main, and you with your team periodically develop new improved versions. Then you load these updates into the main. In addition to the main branches, there are also auxiliary branches: feature, hotfix and a release. We will talk about them in more detail in the next topic.

Gitflow structure

Gitflow Installation

When it is more or less clear what a Gitflow is and how it works, you can start practicing. And first, of course, you need to install it. To install Gitflow on Linux, run the following command:

$ sudo apt-get install git-flow

To install on a Mac, open a terminal and run:

$ brew install git-flow-avh

For those who have windows, Git for Windows includes Git-flow, but if you want an automated install, follow the automated installation instructions.

Commands

If you are just getting started, first you need to initialize git-flow inside an existing git repository:

$ git flow init

After executing this command, the program will ask you a series of questions about which branches you want to use as main, which to develop, and which to make auxiliary. As develop, you need to choose one of your already created branches or create it separately in advance. For other branches, you can leave the default values. Then their branch names will match the names of their model schema.
Then you will immediately be taken to the develop branch and can start working.

Conclusion

You've figured out the basic concepts of the gitflow model, installed it, and initialized your first gitflow repository. You are now ready to dive further and learn how to successfully and effectively work with gitflow.

Read more on this topic in Bridging the Gap by Understanding DevOps on Hyperskill Blog.

139 learners liked this piece of theory. 7 didn't like it. What about you?
Report a typo