Git & GitHub Interview Question #137

What is trunk-based development?

Security, Team Workflows, Troubleshooting & Senior Git/GitHub Scenarios Senior Advanced

Quick Interview Answer

Trunk-based development keeps developers integrating frequently into a single primary branch, often called main or trunk. Feature branches, when used, are normally short-lived and changes are kept small.

Detailed Explanation

Trunk-based development keeps developers integrating frequently into a single primary branch, often called main or trunk. Feature branches, when used, are normally short-lived and changes are kept small.

The approach depends heavily on automated testing, CI, disciplined integration, and often feature flags for incomplete user-facing functionality. Its goal is to reduce long-running branch divergence and difficult merges.

Code Example

git switch main
git pull --ff-only
git switch -c short-lived-change

# Keep the change small and integrate quickly.
git add .
git commit -m "Add validation improvement"
git push -u origin short-lived-change