Git Notes
Explore popular Git branching strategies including GitFlow, GitHub Flow, and trunk-based development. Learn when to use each strategy for your team and project.
A branching strategy defines how your team creates, names, and merges branches. The right strategy depends on your team size, release frequency, and project complexity.
Why Branching Strategies Matter
Without a clear branching strategy:
- Developers step on each other's work
- Releases become unpredictable
- Hotfixes are difficult to deploy
- Code review processes break down
Popular Branching Strategies
GitHub Flow (Simple)
Best for: Continuous deployment, small teams, web applications
Rules:
mainis always deployable- Create feature branches from
main - Open a Pull Request for discussion
- Merge to
mainafter review - Deploy immediately after merge
# GitHub Flow in practice
git checkout main
git pull origin main
git checkout -b feature/user-auth
# Work on feature...
git add .
git commit -m "Add user authentication"
git push origin feature/user-auth
# Open PR on GitHub, get review, mergeGitFlow (Structured)
Best for: Scheduled releases, larger teams, versioned software
Branches:
main— production-ready codedevelop— integration branchfeature/*— new featuresrelease/*— release preparationhotfix/*— urgent production fixes
# Start a new feature
git checkout develop
git checkout -b feature/shopping-cart
# Finish feature
git checkout develop
git merge feature/shopping-cart
# Create release
git checkout -b release/1.0 develop
# ... testing and bug fixes ...
git checkout main
git merge release/1.0
git tag v1.0
# Hotfix
git checkout -b hotfix/critical-bug main
# ... fix ...
git checkout main
git merge hotfix/critical-bug
git checkout develop
git merge hotfix/critical-bugTrunk-Based Development
Best for: Experienced teams, CI/CD pipelines, microservices
Rules:
- Everyone commits to
main(or very short-lived branches) - Feature flags hide incomplete features
- Branches live at most 1-2 days
- Continuous integration runs on every push
# Trunk-based: short-lived branches
git checkout main
git pull
git checkout -b fix/button-color
# Quick fix (same day)
git add .
git commit -m "Fix button color on mobile"
git push origin fix/button-color
# Merge PR immediately after CI passesStrategy Comparison
| Factor | GitHub Flow | GitFlow | Trunk-Based |
|---|---|---|---|
| Complexity | Low | High | Low |
| Release type | Continuous | Scheduled | Continuous |
| Team size | Small-Medium | Medium-Large | Any |
| Branch lifetime | Days | Days-Weeks | Hours-1 Day |
| Parallel releases | No | Yes | No |
| Hotfix process | Simple | Defined | Simple |
| CI/CD requirement | Recommended | Optional | Required |
Branch Naming Conventions
Consistent naming helps everyone understand the purpose of each branch:
# Feature branches
feature/user-authentication
feature/JIRA-123-payment-gateway
feat/add-search-bar
# Bug fix branches
bugfix/login-redirect
fix/null-pointer-exception
# Hotfix branches
hotfix/security-patch
hotfix/v2.1.1
# Release branches
release/1.0.0
release/2024-Q1
# Experimental branches
experiment/new-ui-framework
spike/performance-testingNaming Best Practices
# DO: Use lowercase with hyphens
feature/add-user-profile
# DO: Include ticket numbers
feature/PROJ-456-email-notifications
# DON'T: Use spaces or special characters
feature/Add User Profile # Bad
feature/add_user_profile # Acceptable but inconsistent
# DON'T: Use vague names
feature/updates # Bad - what updates?
feature/fix # Bad - fix what?Choosing the Right Strategy
Ask these questions:
- How often do you release? Daily → GitHub Flow or Trunk-Based; Weekly/Monthly → GitFlow
- How many developers? 1-5 → GitHub Flow; 5+ → GitFlow or Trunk-Based
- Do you support multiple versions? Yes → GitFlow; No → GitHub Flow
- Is CI/CD mature? Yes → Trunk-Based; Growing → GitHub Flow
- Are developers experienced with Git? Mixed → GitHub Flow; Advanced → Trunk-Based
Interview Questions
- What branching strategy would you recommend for a startup with 3 developers deploying daily?
GitHub Flow — it is simple, supports continuous deployment, and does not add unnecessary process overhead for a small team.
- When would you choose GitFlow over GitHub Flow?
When you need to support multiple release versions simultaneously, have scheduled releases, or work with a larger team that needs clear separation between development and production code.
- What are the key principles of trunk-based development?
Small frequent commits to main, very short-lived branches (hours not days), feature flags for incomplete work, strong CI/CD pipeline, and automated testing.
- How do you handle hotfixes in different branching strategies?
In GitHub Flow, branch from main and merge back. In GitFlow, create a hotfix branch from main, fix, merge to both main and develop. In trunk-based, commit directly to main with an expedited review.
- What is the role of feature flags in branching strategies?
Feature flags decouple deployment from release. Code can be merged to main without being visible to users, enabling trunk-based development and reducing long-lived branches.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Branch Strategies - Choosing the Right Git Branching Model.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Git & GitHub topic.
Search Terms
git-github, git & github, git, github, branching, and, merging, branch
Related Git & GitHub Topics