Branching Strategies
A branching strategy is your team’s agreement on how changes travel from idea to production.
On this page · 5 min · Beginner
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 29, 2026
Related tutorials
Interview questions
Learning objectives#
- Create and switch branches
- Compare GitHub Flow, trunk-based and GitFlow
- Name branches consistently
- Tag releases
Explanation#
A branch is a movable pointer to a commit; creating one is cheap. git switch -c feature/login creates and switches.
GitHub Flow: main is always deployable; short-lived feature branches merge via pull requests. Simple and popular.
Trunk-based development: very short branches (hours) or direct commits to main behind feature flags. Best for high-frequency delivery.
GitFlow: develop, release and hotfix branches. Heavier; useful for software with scheduled versioned releases.
Code example: GitHub Flow in practice#
git switch main && git pull
git switch -c feature/product-search
# ...edit, commit in small steps...
git add . && git commit -m "Add product search endpoint"
git push -u origin feature/product-search
# open a pull request → review → CI passes → merge → delete branch
git switch main && git pull
git tag -a v1.4.0 -m "Product search" && git push origin v1.4.0
main always contains reviewed, tested code; v1.4.0 marks exactly what was released.
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- Start from an up-to-date main.
- Work on a short-lived feature branch.
- Merge through a reviewed pull request.
- Tag releases with semantic versions.
Real-world use case#
Most web teams use GitHub Flow with automatic deployment of main.
Common mistakes#
Branches open for weeks create painful merge conflicts. Merge small changes often.
For continuously deployed web apps it adds overhead without benefit.
Best practices#
- Keep branches short-lived
- Name branches feature/, fix/, chore/
- Use feature flags for unfinished work
- Tag releases with semver
Remember this#
Branch = cheap pointer.
GitHub Flow: main + short feature branches + PRs.
Short branches = fewer conflicts.
Practice exercise#
Your task: List all branches including remote ones.
Show solution
git branch -a
Mini quiz#
In GitHub Flow, what is true about main?
Want more? Practise all DevOps MCQs · DevOps interview questions
My notes#
Saved in this browser.