Git flow that's simple, easy to manage, and generally applicable
Alireza Razinejad
Posted on July 16, 2024
This Git flow ensures a structured and organized development process, making it easier to manage changes, track progress, and maintain the stability of the main codebase while incorporating a dedicated branch for QA testing.
Branching Strategy
Main Branches
-
main
: This branch contains the production-ready code. Every commit tomain
should be a release. -
develop
: This branch contains the latest development changes. It is the integration branch for feature branches.
Supporting Branches
-
feature/*
: These branches are used to develop new features. They branch off fromdevelop
and are merged back intodevelop
once the feature is complete. -
bugfix/*
: These branches are used to fix bugs found in thedevelop
branch. They branch off fromdevelop
and are merged back intodevelop
once the bug is fixed. -
release/*
: These branches support the preparation of a new production release. They allow for minor bug fixes and preparing meta-data for a release (version number, build date, etc.). They branch off fromdevelop
and are merged into bothdevelop
andmain
. -
hotfix/*
: These branches are for critical fixes that need to be applied directly to themain
branch. They branch off frommain
and are merged back into bothmain
anddevelop
.
Workflow
Feature Development
-
Create a new feature branch from
develop
:
git checkout develop git pull origin develop git checkout -b feature/your-feature-name
Develop your feature.
-
Once the feature is complete and tested locally, push it to the remote repository:
git push origin feature/your-feature-name
Create a merge request (MR) from
feature/your-feature-name
todevelop
.
Bug Fixing
-
Create a new bugfix branch from
develop
:
git checkout develop git pull origin develop git checkout -b bugfix/your-bugfix-name
Fix the bug.
-
Once the bug is fixed and tested locally, push it to the remote repository:
git push origin bugfix/your-bugfix-name
Create a merge request (MR) from
bugfix/your-bugfix-name
todevelop
.
Preparing a Release
-
When all the features for the next release are merged into
develop
, create a new release branch:
git checkout develop git pull origin develop git checkout -b release/0.0.1
Perform final testing and bug fixing on the
release/0.0.1
branch.-
Once the release is ready, merge it into
main
:
git checkout main git pull origin main git merge release/0.0.1 git push origin main
-
Also, merge it back into
develop
to keep it updated:
git checkout develop git pull origin develop git merge release/0.0.1 git push origin develop
-
Delete the release branch:
git branch -d release/0.0.1 git push origin --delete release/0.0.1
Hotfixes
-
Create a hotfix branch from
main
:
git checkout main git pull origin main git checkout -b hotfix/your-hotfix-name
Fix the issue.
-
Once the hotfix is complete, merge it into
main
:
git checkout main git pull origin main git merge hotfix/your-hotfix-name git push origin main
-
Also, merge it into
develop
to keep it updated:
git checkout develop git pull origin develop git merge hotfix/your-hotfix-name git push origin develop
-
Delete the hotfix branch:
git branch -d hotfix/your-hotfix-name git push origin --delete hotfix/your-hotfix-name
Merging Rules
-
Feature/Bugfix to Develop: A feature or bugfix branch must pass code review and be tested locally before being merged into
develop
. -
Release to Main: The release branch must pass final QA testing before being merged into
main
. -
Hotfix to Main and Develop: Hotfix branches should be used for critical issues in the production environment and must be merged into both
main
anddevelop
after fixing.
Conclusion
This Git flow provides a clear and straightforward process for managing development, testing, and releases. By using dedicated branches for features, bug fixes, QA testing, and hotfixes, it ensures code quality and stability, making it easier to track progress and maintain the main codebase.
Posted on July 16, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.