๐ฏ Goal: Learn what Trunk-Based Development is and how to use it using a very basic HTML project (myshop-demo).
๐ก No big branches. No long pull requests. Just fast commits to main โ like a continuous conveyor belt of improvements.
๐ง What Is Trunk-Based Development?
Everyone works in one branch, usually main, and commits small, frequent changes.
Optionally, short-lived feature branches (1โ2 hours max) are used and merged quickly.
** โ Pros | โ Caution ** |
---|---|
Simple, fast, and clean | Risky without automated testing |
Great for CI/CD & small teams | Requires discipline (no broken code) |
Ideal for feature flags & toggles | Not for teams with slow release cycles |
๐ Project: MyShop Demo
Letโs say you want to:
- Add a message: โWelcome Offer: 10% Offโ
- Add a wishlist button (optional toggle)
Instead of creating feature branches, weโll do everything in main.
๐งช Letโs Do It โ Step-by-Step
โ
Step 1: Initialize Your Project
mkdir myshop-demo
cd myshop-demo
git init
echo "<h1>Welcome to MyShop</h1>" > index.html
git add .
git commit -m "Initial MyShop homepage"
โ Step 2: Make a Small Change on main
Letโs simulate a welcome offer banner.
echo "<p>๐ Welcome Offer: 10% Off</p>" >> index.html
git commit -am "Add welcome offer banner"
โ You just committed directly to main โ no feature branch.
โ Step 3: Add Wishlist Button Behind a Feature Flag
Simulate a feature toggle (this is common in Trunk-Based Dev):
echo "<!-- TODO: Show Wishlist button when feature flag enabled -->" >> index.html
git commit -am "Add wishlist TODO comment (feature flag off)"
โ Feature is part of the codebase, but not active yet โ safe!
โ
Step 4: Push to GitHub (Optional)
git remote add origin <your-repo-url>
git branch -M main
git push -u origin main
Now your main branch reflects real-time updates.
๐ง Real-World Example
At companies like Netflix, Google, Facebook, developers:
- Commit multiple times a day to main
- Use automated tests + feature flags
- Avoid long-lived branches and massive PRs
๐ก The focus is on fast feedback, stability, and speed.
๐ Summary
Strategy Element | Trunk-Based Way |
---|---|
Base Branch | main |
Branch lifespan | 0โ1 day (or commit directly) |
Testing | Required via CI |
Deployment | Often automated (CD pipelines) |
Feature flags | Used to toggle incomplete code |
๐ง When Should You Use Trunk-Based Dev?
โ
You have CI/CD pipelines
โ
You want to deploy fast and often
โ
You can write small, safe changes
โ
Your team values rapid feedback
๐ Bonus: Optional Short-Lived Branch (If Needed)
If you're nervous about breaking main, you can use a short branch:
git checkout -b wishlist-button
# Make changes
git commit -am "Add wishlist feature"
git checkout main
git merge wishlist-button
Just merge it quickly โ donโt let it sit for days!
๐ Final Thoughts
Trunk-Based Development isnโt just about Git โ itโs a mindset:
โShip fast. Test often. Donโt wait.โ
โ Itโs perfect for teams using:
- GitHub Actions
- GitLab CI/CD
- CircleCI
- Jenkins pipelines
๐งก Drop a like or comment โ or check out my next post on GitHub Flow or CI/CD-ready branching.
Top comments (3)
So good ๐๐ป
Thanks Vida. I'm aslo Senior DevOps and Cloud Architect. You may connect me over GitHub - github.com/kohlidevops
I have done lot of projects and shared with everyone to learn!
Wowww I followed you and let's learn and grow together ๐๐ช๐ป๐ช๐ป๐ป
Some comments may only be visible to logged-in visitors. Sign in to view all comments.