Git Flow research - RenoMuijsenberg/S3-Festival-Planner-Angular GitHub Wiki

Git Flow research

Motivation

This document contains a research that I needed to do for my school project, I chose for my research to be about Git flow because in school and in the work world git gets used by almost everyone. It is almost a requirement to know about different Git strategy's because it could be a required skill for applying to a job.

Main question

  • How do you use Git flow in a project

Sub questions

  • What is Git flow
  • What are other git strategy's
  • What are the disadvantages of those strategy's
  • How does Git flow work in a groups project

What is Git flow

Git flow is the oldest strategy for managing code with git. It makes it so that the code is easier to manage. It gets used a lot by open source project to monitor the code other people add to the repository.

Branches

In this strategy you have two main branches the main and the development branch. Then you have some smaller branches that also get used like: feature, release and hotfix.

Main

The main branch is used for a stable release on this branch it is not allowed to have bugs or errors. In most cases when you push to the main branch the code gets deployed to a live server automatically.

Development

The development branch is for adding feature to one another. When dev branch is at a stable point a release branch gets made with a release number and then it gets merged for release in main.

Feature

A feature branch is a branch where you add new features. It gets made from the development branch and merged back into it.

Release

The release branch is used for when your code is on the point of going to the live server. On this branch everything gets made ready for deployment. After everything is done it gets merged into main.

Hotfix

The hotfix is a branch that gets used to fix urgent problems. This branch gets made from main and it is directly merged back into is.

Source(s): https://rewind.com/blog/git-branching-strategies-explained/, https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow, https://nvie.com/posts/a-successful-git-branching-model/

What are other git strategy's

GitHub flow

GitHub flow is an easier version of Git flow and it is made with deployment as main thought. This strategy gets used by GitHub itself to develop their site. This strategy is easy to understand and often gets used in smaller project teams.

Branches

With GitHub flow you only have two branches a main and a feature branch.

Main

The main branch is used as stable release this branch should be able to deploy directly to a live server.

Feature

When this branch is made it gets a descriptive name to show what is made on this branch. This branch gets made from main and is merged directly back into main with a pull request.

Gitlab Flow

GitLab flow is the latest in the branching strategy's. It is made with the main tough being correcting the flaws from the other branching strategy's. This does not per definition make it any better. Gitlab flow tries to tone down the complexity from git flow and increase the functionality of Gitlab flow.

Branches

With this strategy you have three branches. The production , the main and the feature branches.

Production

The production branch gets used as live branch. This cant contain any bugs or errors because it gets deployed to the live server directly.

Main

The main branch or in other methods the development branch gets used to add all feature together and everything gets made ready for production on this branch.

Feature

On this branch get made and are merged back into main.

Source(s): https://rewind.com/blog/git-branching-strategies-explained/, https://www.flagship.io/git-branching-strategies/

What are the disadvantages of those strategy's

Disadvantages of Git flow

A disadvantage from this is that when a feature is long on its own branch it could cause a lot of merge conflicts because things are already pushed to the dev from when you last pulled. It also is not the best for continuous integration.

Disadvantages of GitHub flow

When there are a lot of feature being made at the same time, it could happen that the pull request are quickly unmanageable this could cause merged conflict in the main branch. When all the pull request are accepted each pull request fire a deployment to the live server which could be slow and lead to missing deadlines.

Disadvantages of Gitlab flow

This is a very flexible method where it could be a bit different for every project. That is why it is a must to always have a documentation of how to use this method exactly within your team. There are some optional branches that get used in this strategy but this is up to a team to decide and it could increase complexity.

Source(s): https://rewind.com/blog/git-branching-strategies-explained/, https://www.arpatech.com/blog/git-branching-model-types-pros-cons/

How does Git flow work in a groups project

We decided to use Git flow as branching strategy for our group project. We showed everyone how to initialise Git flow locally. After that everyone could use a git able terminal to use Git flow commands like making a new feature. But after a while we stumble upon an inconvenience in the way we used Git flow. The inconvenience was that when you want to finish a feature it automatically merges back into the dev branch but since we protected this branch with a 'review required' it locally merged the branch but didn't push the changes to the live version. We thought of a few solutions to this problem.

  • Solution 1: Remove the branch protection from the branch, this is of course not a good solution as it increases the change on errors in our code.
  • Solution 2: Make everyone owner of the repo, for obvious reasons this is not a good option. It allows the risk of mistakes/errors and some people sometimes don't know what to do and just click buttons.
  • Solution 3: Search an other option within Git flow that keeps branch protection and does not increase the risk on bugs.

We obviously chose for option 3. So we searched through all the Git flow commands that where available to us and found out that instead of the command 'git flow feature finish' we just can push it to its own origin branch and from there create a pull request that needs the user reviews. After that you only need to checkout to the dev branch and delete the feature branch manually.

How do you use Git flow in a project

To add Git flow to your repository when on a Windows machine you need to install Git for windows. After you installed it you can initialise Git flow with the command Git flow init, this command creates the needed branches for Git flow. When using this command you get some options in the console as to what the branches are called you want to use. You can keep pressing 'enter' to use the default branches within Git flow. image

Feature branch

When you want to create a feature branch you can use git flow feature start {feature_name}, this will create a feature/{feature_name} branch in your local git repo and checkout to this branch. After this you can and start to develop your feature. When you are done creating the feature you can finish the feature with git flow feature finish {feature_name}, this will merge the feature back into the development branch and also checkout to this branch.

Release branch

When the development branch has enough features for the main branch and is ready for a release you will create a release branch. When this branch is created it will start a release cycle this means that no new features will be added to this branch only bug fixes and documentation related changes. When the release branch is ready to be deployed to the main branch this branch gets merged into main with a version number. The release branch gets created by using the command git flow release start {version number}, and when the release branch is done it gets release with git flow release finish {version number}.

Hotfix branch

The hotfix branch gets used the quickly patch bugs/errors in the release branch. This achieves that your can work on the release branch without having interruption when fix bugs. You can create a hotfix branch by using the command: git flow hotfix start {hotfix_name} and when the fix is done you can finish it with: git flow hotfix finish {hotfix_name}.

Soure(s): https://medium.com/swlh/using-gitflow-in-your-project-928d52e22f27, https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow

Conclusion

In this project whe sought to find an answer to the question 'How do you add Git flow to a project?'. For this I sought to answer the questions: What is git flow, What git strategies are also available, What are the disadvantages of those strategies. I made this research paper using the DOT framework.

So it turned out that when you install the git for Windows tool, it comes with the toolkit to use Git flow. From this toolkit you can run a command to initialise Git flow in a project. You'll then be asked a couple of questions about which branches it should use for specific tasks. The next time you run one of Git flows commands it automatically knows what branch / branch prefix it needs to use for that command and what it needs to do when finishing the task.

A downside of using Git flow is that it is not great for using it when your project uses a continuous integration process. When someone works on a feature for a long time, you will quickly see that it is quite easy to get merge conflicts, how longer on its own feature branch how more and more complex the merge conflict will get.

Whether or not Git flow is convenient to use is different for each project. You have to see for yourself/ decide with a team Git flow is the way to go for your project. If not you can always consider a different branching strategy or think of one yourself.

Read next: Cors research