In real-world projects, teams rarely work directly on main.
Instead, they introduce a development branch (dev) to:
- protect stable code
- manage ongoing work
- reduce risk
- organize releases
main→ production-ready, stable codedev→ active development branch
main: A --- B --- C (stable)
\
dev: D --- E --- F (development)
👉 main stays clean
👉 dev keeps evolving
gitGraph
commit id: "A"
commit id: "B"
commit id: "C"
branch dev
checkout dev
commit id: "D"
commit id: "E"
commit id: "F"
checkout main
Branches are stored in:
.git/refs/heads/Example:
main → commit-hash-C
dev → commit-hash-F
.git/HEADPoints to current branch:
ref: refs/heads/dev
When working with dev:
- commits are added to dev branch
- main remains unchanged
- commit graph diverges
- later merged into main
git switch -c devgit add .
git commit -m "New feature"git switch main
git merge dev- developers push to
dev mainis updated only after testing
dev→ staging environmentmain→ production deployment
- stabilize
dev - merge to
main - tag release
main
\
dev
├── feature-login
├── feature-dashboard
└── bugfix-header
git branch dev
git switch devOR
git switch -c devgit switch main
git switch devgit switch main
git merge devgit push -u origin dev👉 Risky — can break production
git pull👉 Causes huge merge conflicts
👉 Use feature branches inside dev
- use
mainonly for stable code - use
devfor integration - create feature branches from
dev - merge regularly
- test before merging to main
main
\
dev
\
feature-x
Flow:
- feature branch → dev
- dev → main
Q: What is the difference between main and dev branches?
Answer:
The main branch represents stable, production-ready code, while the dev branch is used for integrating ongoing development work. Developers typically create feature branches from dev, merge them into dev, and once stable, dev is merged into main.
main = stable dev = development
- main = production-ready
- dev = active development
- dev receives frequent changes
- main receives tested changes
- Why should you avoid working directly on main?
- What is the role of dev branch?
- Where should feature branches originate?
- When should dev be merged into main?
Go to: 08-hotfix-branch.md