Feature Branch Workflow
The Feature Branch Workflow is one of the most popular Git workflows. It's simple, flexible, and works great for teams of any size.
Core Concept
Every new feature or fix gets its own branch:
main: ─────●─────────●─────────●─────
↑ ↑ ↑
feature-a: └──●──●──→│ │
│ │
feature-b: └──●──●──→│
│
bugfix-x: └──●──→
mainis always stable/deployable- Features are developed in isolation
- Branches are merged via pull requests
- Feature branches are deleted after merging
The Workflow
Step 1: Update Main
git checkout main
git pull origin main
Step 2: Create Feature Branch
git checkout -b feature/user-authentication
Step 3: Develop
# Make changes
git add .
git commit -m "Add login form"
# More changes
git add .
git commit -m "Add password validation"
# Push to remote
git push -u origin feature/user-authentication
Step 4: Stay Updated
# Periodically sync with main
git fetch origin
git merge origin/main
# or
git rebase origin/main
Step 5: Create Pull Request
On GitHub:
- Open a pull request
- Request reviews
- Address feedback
- Get approval
Step 6: Merge
After approval:
- Merge the PR (on GitHub)
- Delete the feature branch
Step 7: Clean Up Locally
git checkout main
git pull origin main
git branch -d feature/user-authentication
Branch Naming Conventions
| Prefix | Use Case |
|---|---|
feature/ | New features |
bugfix/ | Bug fixes |
hotfix/ | Urgent production fixes |
refactor/ | Code refactoring |
docs/ | Documentation |
test/ | Test additions |
Examples:
feature/user-authentication
feature/shopping-cart
bugfix/login-redirect
hotfix/security-patch
docs/api-documentation
Merge Strategies
Merge Commit
git checkout main
git merge --no-ff feature/user-auth
Preserves branch history with a merge commit.
main: ─────●───────────●───────
\ /
feature: ●───●───●
Squash Merge
Combines all feature commits into one:
main: ─────●───────────●───────
↑
(all feature commits squashed)
Cleaner history but loses individual commits.
Rebase and Merge
Replays commits on top of main:
main: ─────●───────────●──●──●──
↑
(feature commits rebased)
Linear history, as if developed sequentially.
Best Practices
Keep Branches Short-Lived
- Days, not weeks
- Smaller changes = easier reviews
- Less merge conflict risk
One Purpose Per Branch
❌ Bad:
git checkout -b feature/auth-and-cart-and-refactor
✅ Good:
git checkout -b feature/authentication
git checkout -b feature/shopping-cart
git checkout -b refactor/database-layer
Sync Frequently
# At least daily
git fetch origin
git merge origin/main # or rebase
Prevents large, complex merge conflicts.
Delete After Merging
# Local
git branch -d feature/completed-feature
# Remote
git push origin --delete feature/completed-feature
Keep your branch list clean.
Exercise: Feature Branch
Practice the feature branch workflow:
Handling Long-Running Features
For features that take longer:
Option 1: Regular Integration
# Merge main into feature regularly
git checkout feature/big-feature
git merge origin/main
# Resolve conflicts if any
git push
Option 2: Break Into Smaller Features
feature/auth-models (merge first)
feature/auth-api (merge second)
feature/auth-ui (merge third)
Option 3: Feature Flags
Merge incomplete code behind a flag:
if (FEATURE_FLAGS.newAuth) {
// New authentication code
} else {
// Old authentication code
}
When to Use This Workflow
| Good For | Not Ideal For |
|---|---|
| Small to medium teams | Highly regulated releases |
| Continuous deployment | Multiple parallel releases |
| SaaS applications | Complex release schedules |
| Agile development |
Summary
- Every feature gets its own branch
- Main stays stable and deployable
- Use descriptive branch names with prefixes
- Create PRs for code review
- Delete branches after merging
- Sync with main frequently
- Keep branches short-lived
In the next lesson, we'll explore Gitflow—a more structured branching model.

