0
0
GitConceptBeginner · 3 min read

Trunk Based Development in Git: What It Is and How It Works

Trunk based development in git is a workflow where all developers work on a single main branch called trunk or main. Developers make small, frequent commits directly to this branch or short-lived feature branches merged quickly, ensuring continuous integration and reducing merge conflicts.
⚙️

How It Works

Imagine a team working on a shared document where everyone writes on the same page instead of separate copies. In trunk based development, the "trunk" is like that shared page — the main branch where all changes happen. Developers either commit directly or create very short-lived branches that merge back quickly.

This approach keeps the codebase simple and up to date. Since everyone integrates their work often, it avoids big surprises or conflicts later. It’s like cleaning your room a little every day instead of letting it pile up.

💻

Example

This example shows creating a short-lived feature branch, making a change, and merging it back to main quickly.

bash
git checkout main
# Make sure main is up to date
git pull origin main

git checkout -b feature-quick-fix
# Make your changes here, e.g., edit a file

git add .
git commit -m "Quick fix on feature"

git checkout main
git merge feature-quick-fix

git push origin main

git branch -d feature-quick-fix
Output
Switched to branch 'main' Already up to date. Switched to a new branch 'feature-quick-fix' [feature-quick-fix abc1234] Quick fix on feature Switched to branch 'main' Updating abc1234..def5678 Fast-forward file.txt | 1 + 1 file changed, 1 insertion(+) To origin/main def5678..ghi9012 main -> main Deleted branch feature-quick-fix (was abc1234).
🎯

When to Use

Use trunk based development when you want fast feedback and fewer merge problems. It works well for small to medium teams that deploy often or practice continuous integration and delivery.

It’s great for projects where keeping the main branch stable and up to date is important, like web apps or services updated daily. Avoid long-lived branches that delay merging, as they can cause conflicts and slow down progress.

Key Points

  • All work happens on a single main branch called trunk or main.
  • Feature branches are short-lived and merged quickly.
  • Frequent commits reduce merge conflicts and integration issues.
  • Supports continuous integration and fast delivery.
  • Helps teams keep code stable and up to date.

Key Takeaways

Trunk based development means working mostly on one main branch with quick merges.
It reduces merge conflicts by integrating changes frequently.
Short-lived feature branches keep the codebase simple and stable.
Ideal for teams practicing continuous integration and fast delivery.
Avoid long-lived branches to maintain smooth collaboration.