Day 8 - Git Branching Strategy β Real-World Explanation
π§ 1. Why Branching Strategy is Important
In any software organization, the main goal is to ensure that customers get new features and bug fixes quickly and reliably.
Frequent releases keep users engaged and happy.
Companies like Amazon or Flipkart release updates every 15 days, monthly, or quarterly.
To manage these frequent updates efficiently, a proper branching strategy in Git is essential.
Without a good strategy:
Code merges can become messy.
Teams can overwrite each otherβs work.
Releases can break production.
β A branching strategy helps teams develop, test, and release features smoothly and safely.
π³ 2. What is a Branch in Git?
A branch is a separate line of development created from the main codebase.
It allows developers to work on new features or fixes without disturbing the main code.
π§© Example β Calculator App
Letβs say you have a Calculator App with basic features:
Addition
Subtraction
Multiplication
Division
Now you want to add version 2 (V2) with new features like:
Percentage
Advanced calculations
Instead of changing the main branch (main/master) directly, you create a new branch called:
feature/v2
You:
Develop and test all new code in this branch.
Merge it into the main branch once itβs stable.
Delete the feature branch after merging.
β This ensures the main branch stays stable until changes are fully tested.
π΅ Real Example β Uber
Initially, Uber only supported Cabs.
Later, they wanted to add Bikes as a new service.
Steps:
Developers created a new branch called
feature/bikes.They developed and tested the new βbikeβ code independently.
Once confident it works, they merged it back into the main branch.
The βfeature/bikesβ branch was deleted after merging.
π§© Reason: The main βCabβ app kept running without being affected by incomplete βBikeβ code.
βοΈ 3. Types of Branches in a Good Strategy
A good Git branching strategy generally involves four key branch types:
| Branch Type | Purpose |
| Main (Master) | Central branch, always stable and up-to-date |
| Feature Branch | For developing new features or modules |
| Release Branch | For preparing and testing production-ready releases |
| Hotfix Branch | For urgent production fixes |
Letβs break each one down π
π§± 3.1 Main (or Master) Branch
The default branch in any repository.
Contains the latest stable code.
All tested and approved changes are merged here.
Active development happens through feature branches, not directly on master.
π 3.2 Feature Branch
Created for new features or major changes.
Keeps risky changes isolated from stable code.
Once feature is tested β merged into main branch.
Example:
feature/percentage
feature/exponential
feature/division
β
Developers work independently on each feature.
β
After validation, all are merged into main.
π 3.3 Release Branch
Created when a product is ready for deployment.
Example:
release/v1.0 release/v2.0Purpose:
Final testing before going live.
Avoids last-minute changes entering the release.
Ensures stability while active development continues in
main.
Why not release directly from main?
Because
mainoften has ongoing development.Release branches allow controlled testing and deployment.
β
Once tested β build & ship from release branch.
β
Post-release, merge it back into main.
π₯ 3.4 Hotfix Branch
Used for critical production bugs.
Short-lived (1β2 days).
Example:
hotfix/login-issue
Steps:
Create from the latest release branch.
Fix the bug, test it.
Merge it into both:
main(so the latest code stays updated)release(so the fix goes live)
β Ensures both development and production have the fix.
π§© 4. Real-World Example β Kubernetes Project
Kubernetes (open-source, hosted on GitHub) follows a similar branching strategy.
Over 3,300 contributors collaborate on the codebase.
They maintain:
A main/master branch for active development.
Multiple feature branches like:
feature/rate-limitingfeature/server-setfeature/workload-GA
Release branches for versions:
release-1.26release-1.27
π¦ Kubernetes Release Flow:
Developers work on feature branches.
Merge changes into master after review.
Create a release branch for the next version (e.g.,
release-1.27).Test and stabilize this branch.
Ship this code to users.
β
After the release, all new features continue on master.
β
The release branch code represents what customers use.
π§ 5. Visual Summary
+---------------------+
| MAIN/MASTER | β Always stable, latest code
+---------------------+
β β
(merge) / \ (merge)
+-----------+ +------------+
| Feature 1 | | Feature 2 | β Feature branches for new work
+-----------+ +------------+
β
β (Once stable)
β
+--------------------+
| Release Branch | β Used for testing & shipping builds
+--------------------+
β
β (Deployed)
β
+--------------------+
| Production Code |
+--------------------+
β
β
+--------------------+
| Hotfix Branch | β Urgent production fixes
+--------------------+
π§© 6. How It Works in an Example Project (Uber)
| Step | Action |
| 1 | Uber starts with master branch (only Cab feature). |
| 2 | Product team decides to add Bikes β create feature/bikes. |
| 3 | Developers build and test the bike feature. |
| 4 | Once stable β merge back into master. |
| 5 | Later, they introduce Intercity rides β feature/intercity. |
| 6 | Merge that feature too once tested. |
| 7 | After a few months β create release/v3 from master. |
| 8 | Perform testing, fix bugs, and deploy the release branch. |
β The cycle repeats for every version.
π§© 7. Interview-Focused Summary
| Question | Answer |
| What is a Feature Branch? | Created for new or breaking changes. Merged after testing. |
| What is a Release Branch? | Used for final testing and release to customers. |
| What is a Hotfix Branch? | Created for urgent production fixes and merged into both main & release. |
| Which Branch is Always Up-to-date? | master (or main) |
| From which Branch are Releases Made? | Always from the release branch. |
β 8. Best Practices
Keep
mainbranch always clean and stable.Always create feature branches for new changes.
Merge changes only through pull requests (PRs).
Create release branches for testing before deployment.
Merge hotfixes into both release and main branches.
Delete stale branches once merged.
π 9. Summary
| Branch Type | Description | Lifetime |
| Main/Master | Stable, production-ready code | Permanent |
| Feature | For developing new features | Temporary |
| Release | For testing and deploying new versions | Per release |
| Hotfix | For urgent production fixes | Short-lived |
β All changes eventually merge back into main so it stays the latest and most complete version.
In Short:
Developers build features in feature branches.
Test and deploy from release branches.
Fix urgent bugs via hotfix branches.
Keep master branch always clean and updated.