# Hot it Works

## What Is Gitflow?

[Gitflow](http://nvie.com/posts/a-successful-git-branching-model/) is a branching model for Git, created by [Vincent Driessen](https://nvie.com/about/).\
It has attracted a lot of attention because it is very well suited to collaboration and scaling the development team.

![Gitflow](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-139fc3edfb22f8fcb6f49ac9f03259aabc328334%2Fgitflow-overview.webp?alt=media)

## How It Works

### Feature Branches

New development (new features, non-emergency bug fixes) are built in **feature branches**:

![GitFlow feature branches](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-d8ac8297f430fc1fad05c4a8a18d5269ae127f4d%2FGitFlowFeatureBranches.png?alt=media)

Feature branches are branched off of the **develop branch**, and finished features and fixes are merged back into the \_\_ develop branch\_\_ when they're ready for release:

![GitFlow develop branch](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-b1d1466b466371d55f7af216ab84632d7df6c107%2FGitFlowDevelopBranch.png?alt=media)

### Release Branch

When it is time to make a release, a **release branch** is created off of **develop**:

![GitFlow release branch](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-648896247bb301cd3d183ca48f29e07bef5f6d35%2FGitFlowReleaseBranch.png?alt=media)

The code in the **release branch** is deployed onto a suitable test environment, tested, and any problems are fixed directly in the release branch. This **deploy -> test -> fix -> redeploy -> retest** cycle continues until you're happy that the release is good enough to release to customers.

When the release is finished, we generate **CHANGELOG.md** using tools like [git-chglog](https://github.com/git-chglog/git-chglog) from commits.

Then, the **release branch** is merged into **master** **and** into **develop** too, to make sure that any changes made in the **release branch** aren't accidentally lost by new development.

![GitFlow main branch](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-848b00ba2690a14067317d9995568e3f0e76c958%2FGitFlowMasterBranch.png?alt=media)

### Master Branch

The **master branch** tracks released code only. The only commits to **master** are merges from **release branches** and **hotfix branches**.

### Hotfix Branches

**Hotfix branches** are used to create emergency fixes:

* Hotfixes arise from the necessity to act immediately upon an undesired state of a live production version
* May be branched off from the corresponding tag on the main branch that marks the production version.

![GitFlow hotfix branch](https://3806442580-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1wLJJ6MRUtU9bO8qPy-659326392%2Fuploads%2Fgit-blob-523f2fa4f5adb4354a644a2a3b042fc2829cfe66%2FGitFlowHotfixBranch.png?alt=media)

They are branched directly from a tagged release in the **master branch**, and when finished are merged back into both **master** and **develop** to make sure that the hotfix isn't accidentally lost when the next regular release occurs.

## Reference

* [BitBucket Gitflow Workflow](https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow)
* [GitFlow Cheat Sheet](http://danielkummer.github.io/git-flow-cheatsheet/)
