0
0
Gitdevops~10 mins

Trunk-based development in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Trunk-based development
Start on trunk (main branch)
Create short-lived feature branch
Develop feature
Merge back to trunk quickly
Run tests on trunk
Deploy from trunk
Repeat for next feature
Trunk-based development means working on a single main branch, creating short-lived branches for features, merging them back quickly to keep code integrated and stable.
Execution Sample
Git
git checkout main
# create feature branch
git checkout -b feature1
# make changes
# commit changes
git checkout main
git merge feature1
This sequence shows creating a feature branch from main, making changes, then merging back to main quickly.
Process Table
StepActionBranchCommit StateResult
1Checkout main branchmainInitial commitOn main branch
2Create feature branch 'feature1'feature1Same as mainNew branch created
3Make changes and commit on feature1feature1One new commitFeature work done
4Checkout main branchmainInitial commitSwitched back to main
5Merge feature1 into mainmainInitial + feature commitFeature integrated
6Delete feature1 branch--Clean up feature branch
💡 Feature branch merged quickly back to main, keeping trunk updated and stable
Status Tracker
VariableStartAfter 1After 2After 3After 4After 5Final
Branchmainmainfeature1feature1mainmainmain
Commit StateInitial commitInitial commitInitial commitInitial + feature commitInitial commitInitial + feature commitInitial + feature commit
Key Moments - 3 Insights
Why do we create short-lived branches instead of working directly on main?
Short-lived branches let you work on features without breaking main. Execution table step 3 shows work on feature1 branch separate from main.
What happens if we wait too long to merge back to main?
Waiting too long causes big merges and conflicts. Trunk-based development merges quickly as shown in step 5 to keep integration smooth.
Why delete the feature branch after merging?
Deleting keeps the repo clean and avoids confusion. Step 6 shows branch deletion after merge.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what branch is active at step 3?
Amain
Bfeature1
Cdevelop
Drelease
💡 Hint
Check the 'Branch' column at step 3 in the execution table
At which step is the feature branch merged back into main?
AStep 5
BStep 2
CStep 4
DStep 6
💡 Hint
Look for the 'Merge feature1 into main' action in the execution table
If we skip deleting the feature branch, what changes in the execution table?
AStep 3 would show main branch
BStep 5 would change branch name
CStep 6 would be missing
DNo changes at all
💡 Hint
Step 6 shows branch deletion; skipping it removes that step
Concept Snapshot
Trunk-based development uses a single main branch.
Create short-lived feature branches.
Merge features back quickly to main.
Keep main branch stable and deployable.
Delete feature branches after merge.
Full Transcript
Trunk-based development is a way to keep all work integrated on one main branch called trunk or main. Developers create short-lived branches for features, work on them, then merge back quickly to avoid conflicts. This keeps the main branch stable and ready for deployment. The process involves checking out main, branching off, committing changes, merging back, and cleaning up branches. This method reduces integration problems and speeds up delivery.