🎯 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.