Hand-on Demo – GitFlow for Continuous Delivery
The GitFlow branching model provides a structured approach for managing features, releases, and hotfixes, which makes it particularly useful for teams handling multiple environments (e.g., development, staging, and production).
Here’s a step-by-step demonstration of GitFlow tailored to a Continuous Delivery (CD) pipeline.
GitFlow Branch Types
main:
The branch for production-ready code.
Only updated by merging release or hotfix branches.
develop:
The integration branch where all feature branches are merged.
Represents the latest stable development code.
feature/:
Temporary branches for developing new features.
Based on
develop.
release/:
Temporary branches for preparing a new release.
Based on
developand merged into bothmainanddevelop.
hotfix/:
Temporary branches for urgent fixes to production.
Based on
mainand merged into bothmainanddevelop.
Scenario: Developing a New Feature and Delivering It Using GitFlow
1. Initial Setup
Clone the repository and set up the default branches:
xxxxxxxxxx61git clone https://github.com/your-repo.git2cd your-repo3
4# Ensure main and develop branches exist5git checkout -b main6git checkout -b develop2. Feature Development
Step 1: Create a Feature Branch
A developer starts a feature branch based on develop:
xxxxxxxxxx21git checkout develop2git checkout -b feature/add-login-pageStep 2: Develop and Commit Changes
Work on the feature and commit code incrementally:
xxxxxxxxxx71# Example changes2echo "<h1>Login Page</h1>" > login.html3git add login.html4git commit -m "Add basic login page structure"5echo "Add form validation" >> login.html6git add login.html7git commit -m "Implement form validation"Step 3: Push the Feature Branch for Review
Push the branch to the remote repository and create a pull request:
xxxxxxxxxx11git push origin feature/add-login-pageThe pull request triggers CI to:
Run unit tests.
Check code quality.
Once approved, the branch is merged into develop:
xxxxxxxxxx31git checkout develop2git merge feature/add-login-page3git push origin develop3. Release Preparation
Step 1: Create a Release Branch
When develop is ready for a production release:
xxxxxxxxxx21git checkout develop2git checkout -b release/v1.0.0Step 2: Finalize the Release
Add release-specific changes (e.g., update version numbers, documentation).
Commit the changes:
xxxxxxxxxx31echo "v1.0.0" > version.txt2git add version.txt3git commit -m "Update version to v1.0.0"Step 3: Push and Test the Release
Push the release branch:
xxxxxxxxxx11git push origin release/v1.0.0Run staging tests or deployment previews in the CI/CD pipeline.
Step 4: Merge into main and develop
After testing is complete:
xxxxxxxxxx131# Merge into main2git checkout main3git merge release/v1.0.04git push origin main5
6# Tag the release7git tag -a v1.0.0 -m "Release v1.0.0"8git push origin v1.0.09
10# Merge back into develop11git checkout develop12git merge release/v1.0.013git push origin developStep 5: Delete the Release Branch
xxxxxxxxxx21git branch -d release/v1.0.02git push origin --delete release/v1.0.04. Hotfix Workflow
If a production bug is discovered:
Create a hotfix branch from
main:xxxxxxxxxx21git checkout main2git checkout -b hotfix/fix-login-bugFix the issue, commit, and push:
xxxxxxxxxx41echo "Fix login issue" >> login.html2git add login.html3git commit -m "Fix login issue in production"4git push origin hotfix/fix-login-bugMerge the hotfix into both
mainanddevelop:xxxxxxxxxx61git checkout main2git merge hotfix/fix-login-bug3git push origin main4git checkout develop5git merge hotfix/fix-login-bug6git push origin developTag and delete the hotfix branch:
xxxxxxxxxx41git tag -a v1.0.1 -m "Hotfix for login issue"2git push origin v1.0.13git branch -d hotfix/fix-login-bug4git push origin --delete hotfix/fix-login-bug
Advantages of GitFlow for Continuous Delivery
Structured Workflow: Clear separation of features, releases, and fixes.
Parallel Development: Enables multiple teams to work on features simultaneously.
Stable
main:** Only deployable code is merged intomain.
Challenges
May slow down CD compared to Trunk-Based Development due to longer release cycles.
Requires discipline to manage multiple branches.






















Leave a Reply