GIT Flow
Tags: devops, programming, tutorial
Published: 2023-01-15 03:58:58

[Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow#:~:text=The%20overall%20flow%20of%20Gitflow,merged%20into%20the%20develop%20branch) is a Git workflow that helps with continuous software development and implementing [DevOps](https://www.atlassian.com/devops/what-is-devops) practices. It was first published and made popular by Vincent Driessen at nvie. The Gitflow Workflow defines a strict branching model designed around the project release. This provides a robust framework for managing larger projects. This is suited for projects that releases are based on a schedule.

Gitflow workflow is not for everybody. But for those who loves and using it below are some shortcuts that can help you understand what is this workflow.

Installing git-flow plugin for git client is plain and simple. For mac-os, easiest to install is `brew install git-flow`. 

**Basic Commands and Configuration**

- git flow init
- git flow feature start/finish <feature branch name>
- git flow release start/finish <release branch name>
- git flow hotfix start/finish <hotfix branch name>
- git merge <from branch>

**Basic Configuration Flow**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z08ks0yavlp4po8mvwqy.png)

**Concurrent Configuration Flow**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u9nneyirdqu4faiivbzw.png)

The overall flow of Gitflow is:

1. A `develop` branch is created from `main`.
2. A `release` branch is created from `develop`.
3. `Feature` branches are created from `develop`.
4. When a `feature` is complete it is merged into the `develop` branch.
5. When the `release` branch is done it is merged into `develop` and `main`.
6. If an issue in `main` is detected a `hotfix` branch is created from `main`.
7. Once the `hotfix` is complete it is merged to both `develop` and `main` and/or `feature` branches.

**Git vs Git Flow Commands**

These are base guidelines that corresponds to some of the git commands used by the git-flow wrapper client. These commands are not fixed in stone. Depending on situations, there are steps that can be altered or change within the course of the development.

Create a develop branch on your local if one doesn’t exists in the repo. 

- Initialisation (specific for git flow only)

```
$ git flow init
Which branch should be used for bringing forth production releases?
   - develop
   - master
Which branch should be used for integration of the "next release"?
   - master
   - develop
Branch name for "next release" development: [develop]

How to name your supporting branch prefixes?
Feature branches? [feature/]
Bugfix branches? [bugfix/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []
Hooks and filters directory? [../../.git/hooks]
```

- Creating feature branches
```
git flow feature start <branch>
```
vs
```
git checkout develop                     # this switches the branch to the develop branch, do a `git pull` to make sure it is latest
git checkout -b feature/<branch>         # this creates a branch named 'feature/<branch>'
git push --set-upstream origin feature/<branch>   # push changes to git repo to a new 'feature/<branch>'
```

- Completed a feature
```
git flow feature finish <branch>
```
vs
```
git checkout feature/<branch>            # this switches the branch to the 'feature/<branch>' if you are not in it, do a `git pull` to make sure it is latest
git checkout develop                     # this switches the branch to the develop branch, do a `git pull` to make sure it is latest
git merge feature/<branch>               # merge feature/branch to develop
git push                                 # push changes to git repo in develop branch
```

- Creating a release branch
```
git flow release start <branch>
```
vs
```
git checkout develop                     # this switches the branch to the develop branch, do a `git pull` to make sure it is latest
git checkout -b release/<branch>         # this creates a branch named 'release/<branch>'
git push --set-upstream origin release/<branch>   # push changes to git repo to a new 'release/<branch>' and this will trigger the BUILD to QA
```

- Release Completed
```
git flow release finish <branch>
```
vs
```
git checkout release/<branch>            # this switches the branch to the 'release/<branch>' if you are not in it, do a `git pull` to make sure it is latest
git checkout develop                     # this switches the branch to the develop branch, do a `git pull` to make sure it is latest
git merge release/<branch>               # merge release/branch to develop
git push                                 # push changes to git repo in develop branch
git checkout main                        # this switches the branch to the main branch, do a `git pull` to make sure it is latest
git merge release/<branch>               # merge release/branch to main
git push                                 # push changes to git repo in main branch
git push --tags                          # push tags
git push -d origin release/<branch>      # delete remote branch
```

- Creating a hotfix
```
git flow hotfix start <branch>
```
vs
```
git checkout main                        # this switches the branch to the main branch, do a `git pull` to make sure it is latest
git checkout -b hotfix/<branch>          # this creates a branch named 'hotfix/<branch>'
git push --set-upstream origin hotfix/<branch>   # push changes to git repo to a new 'hotfix/<branch>' and this will trigger the BUILD to QA
```

- Hotfix Completed
```
git flow hotfix finish <branch>
```
vs
```
git checkout hotfix/<branch>             # this switches the branch to the 'hotfix/<branch>' if you are not in it, do a `git pull` to make sure it is latest
git checkout develop                     # this switches the branch to the develop branch, do a `git pull` to make sure it is latest
git merge hotfix/<branch>                # merge hotfix/branch to develop
git push                                 # push changes to git repo in develop branch
git checkout main                        # this switches the branch to the main branch, do a `git pull` to make sure it is latest
git merge hotfix/<branch>                # merge hotfix/branch to main
git push                                 # push changes to git repo in main branch
```