Hand-on Demo – Git Branch Model for Continuous Delivery
To demonstrate a Git branch model for Continuous Delivery (CD), we can follow a practical example that simulates a simple workflow. Below is a demonstration using the Trunk-Based Development model, as it aligns closely with CD principles.
Scenario: Adding a Feature to a Web Application
1. Setup
Branches:
main: The deployable branch (always in a releasable state).Short-lived feature branches (e.g.,
feature/add-login-page).
Tools:
Git for version control.
CI/CD Pipeline (e.g., GitHub Actions, Jenkins, GitLab CI).
Automated tests to validate code changes.
2. Step-by-Step Workflow
Step 1: Create a Feature Branch
A developer starts by creating a branch to implement a new feature.
xxxxxxxxxx11git checkout -b feature/add-login-pageStep 2: Implement the Feature
The developer writes code for the login page and commits changes incrementally.
xxxxxxxxxx31git add .2git commit -m "Add HTML structure for login page"3git commit -m "Implement basic login validation"Step 3: Push to Remote and Open a Pull Request
The developer pushes the feature branch and opens a pull request (PR) for review.
xxxxxxxxxx11git push origin feature/add-login-pageThe PR triggers the CI pipeline:
Automated tests (unit, integration, end-to-end).
Code style checks (e.g., linting).
Step 4: Review and Merge
Once the PR is approved and tests pass:
The branch is merged into
main.xxxxxxxxxx21git checkout main2git merge feature/add-login-pageA post-merge pipeline runs to validate the merged
mainbranch.
Step 5: Automated Deployment
After merging:
The CI/CD pipeline deploys the
mainbranch to the staging environment.If all staging tests pass, the changes are promoted to production automatically.
3. Branching Model Highlights
Short-Lived Feature Branches: Branches are merged quickly to avoid long-lived divergence.
Continuous Integration: Every branch triggers a CI pipeline, ensuring changes are tested before merging.
Continuous Delivery:
The
mainbranch is always deployable.Feature flags are used to control incomplete features in production.
Git Commands Demonstration
Below is a sequence of commands to demonstrate the process:
xxxxxxxxxx231# Clone the repository2git clone https://github.com/your-repo.git3cd your-repo4
5# Step 1: Create a feature branch6git checkout -b feature/add-login-page7
8# Step 2: Make changes and commit9echo "<h1>Login Page</h1>" > login.html10git add login.html11git commit -m "Add basic login page"12
13# Step 3: Push the feature branch and create a PR14git push origin feature/add-login-page15
16# Step 4: Merge into main after review17git checkout main18git pull origin main19git merge feature/add-login-page20
21# Step 5: Clean up the branch22git branch -d feature/add-login-page23git push origin --delete feature/add-login-page4. Enhancements for Larger Teams
For larger teams or more complex projects:
Use feature flags to release incomplete features safely.
Introduce branch protection rules to enforce CI checks and code reviews before merging.
Implement deployment previews to test changes in isolated environments before merging.
Summary
Would you like me to demonstrate another branching model, such as GitFlow, or create a more detailed example of automated testing and deployment?






















Leave a Reply