Hand-on Demo – GitHub Flow for Continuous Delivery
The GitHub Flow branching model is simple and effective for teams practicing Continuous Delivery (CD). It is lightweight and encourages fast iteration, focusing on short-lived feature branches and automated deployment from the main branch.
GitHub Flow Core Principles
'main' Branch:
The deployable branch.
Code merged into
mainis ready for production.
Short-Lived Feature Branches:
Used for developing new features or fixing bugs.
Merged into
mainvia pull requests (PRs).
Automated CI/CD Pipeline:
Every commit triggers automated tests.
mainbranch deploys automatically to production.
Scenario: Adding a New Feature to a Web Application
1. Initial Setup
Branches:
main: The production-ready branch.feature/add-login-page: A temporary feature branch.
Tools:
Git for version control.
CI/CD pipeline (e.g., GitHub Actions, Jenkins).
Automated tests to validate changes.
2. Workflow Steps
Step 1: Create a Feature Branch
The developer creates a new branch from main for the feature:
xxxxxxxxxx21git checkout main2git checkout -b feature/add-login-pageStep 2: Implement Changes
Develop the feature and commit changes incrementally:
xxxxxxxxxx91# Example change: Create a login page2echo "<h1>Login Page</h1>" > login.html3git add login.html4git commit -m "Add login page structure"5
6# Add form validation7echo "Add form validation" >> login.html8git add login.html9git commit -m "Implement form validation"Step 3: Push and Open a Pull Request
Push the feature branch to the remote repository and open a pull request:
xxxxxxxxxx11git push origin feature/add-login-pageCI pipelines are triggered to:
Run automated tests.
Check for code quality issues (e.g., linting).
Step 4: Code Review and Merge
Once the pull request is approved and tests pass:
Merge the feature branch into
main:xxxxxxxxxx31git checkout main2git merge feature/add-login-page3git push origin mainAlternatively, perform a squash and merge via the GitHub UI to keep a cleaner history.
Step 5: Automated Deployment
The CI/CD pipeline automatically deploys the updated main branch to production:
Example with GitHub Actions:
xxxxxxxxxx251nameCI/CD Pipeline2on3 push4 branches5main6jobs7 build-and-deploy8 runs-onubuntu-latest9 steps10nameCheckout code11 usesactions/checkout@v312nameSet up Node.js13 usesactions/setup-node@v314 with15 node-version1616nameInstall dependencies17 runnpm install18nameRun tests19 runnpm test20nameDeploy to production21 env22 DEPLOY_KEY$ secrets.DEPLOY_KEY 23 run24 echo "Deploying to production..."25 ./deploy.shStep 6: Clean Up the Feature Branch
Delete the feature branch after merging:
xxxxxxxxxx21git branch -d feature/add-login-page2git push origin --delete feature/add-login-pageGit Commands Summary
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 branch and open a pull request14git push origin feature/add-login-page15
16# Step 4: Merge into main after review17git checkout main18git merge feature/add-login-page19git push origin main20
21# Step 5: Clean up the branch22git branch -d feature/add-login-page23git push origin --delete feature/add-login-pageAdvantages of GitHub Flow for Continuous Delivery
Simplicity: Fewer branches and less overhead.
Rapid Iteration: Short-lived feature branches enable faster delivery.
Always Deployable: The
mainbranch is always production-ready.Built-in CI/CD: Fully automated testing and deployment pipelines.
Challenges
Limited support for long-term development or multiple versions.
Requires a robust CI/CD pipeline to maintain
mainbranch quality.






















Leave a Reply