A successful Git branching model
Main Branches
- master
- develop
Supporting brach
- Release
- Hotfix
- Feature
Feature Branches
Feature branches are used to develop a new feature for an upcoming or distant future release.
Feature branches only exist in developers repos only i.e. in their machine, not in origin i.e. remote.
- branch from develop
- must be merged back in develop
- Naming convention -> Anything except
- master
- develop
- release-*
- hotfix-*
Creating a feature branch
After finishing the feature and merge back to develop
Sourcetree Version
<strong style="color:red">Take pull before pushing your code if pull is available.</strong>
It is impossible to see from git history of which commit objects together implement a feature. You would have to manually read all commit messages. If you need to revert particular feature, it is true headache in later situations, whereas it is easy with --no-ff flag was used.
It will create more empty commits but the gain is much bigger than cost.
Release Branches
- Branch from develop
- Must merge back in develop and master
- Branch naming conventions
- release-*
Creating release branch
You have to collect release notes from commit you can type one. Bump version to 1.2.1 as matches with your release branch name.
Finishing release branch
To keep changes made by release branch, we need to merge in develop
This may lead to merge conflict. If so, fix and commit it.
Hotfix Branches
- Branch from master
- Must merge back in develop and master
- Branch naming conventions
- hotfix-*
Hotfix branches are very much like release branches in that they are meant to prepare for production, albeit unplanned. When a critical bug in production version must be resolved immediately, a hotfix branch may be branch of from corresponding tag on master branch that marks production version.
Creating hotfix branch
Don't forget to bump a version after branching off.
Then fix the bug and commit changes
Finishing hotfix branch
When finished the bug fixed, we need to merge back in master as well as develop branch, in order to safeguard that the bug fix also include in next release as well.
The one exception rule is that, When a release branch currently exists, the hotfix branch need to be merge in release branch instead of develop. Back merging the bug fix into release branch eventually result in the hotfix branch merge in develop too, when release branch is finished. (If work in develop immediately require the hotfix and cannot wait it fo release branch to finish, you can safely merge in develop branch now already as well.)
Information
You can find full documentation and explanation here. Feel free to check it out.
Other links to learn and embrace the power of Git.