Learn professional Git workflows used by development teams worldwide. Master Feature Branch workflow, Gitflow, GitHub Flow, and choose the right workflow for your project.
While Git provides the tools for version control, workflows define how teams use those tools effectively. A workflow is an agreed-upon process that teams follow when using Git to collaborate.
The right workflow helps teams:
In this lesson, you'll learn the most popular Git workflows and understand when to use each one.
The Feature Branch workflow is the foundation of most modern Git strategies. Each feature gets its own branch.
Core Principle:
All feature development happens in dedicated branches, not the main branch.
The Process:
1# 1. Start from updated main
2git switch main
3git pull origin main
4
5# 2. Create a feature branch
6git switch -c feature/user-authentication
7
8# 3. Work on the feature (multiple commits)
9git add .
10git commit -m "Add login form"
11git commit -m "Implement JWT authentication"
12git commit -m "Add password hashing"
13
14# 4. Keep up to date with main
15git fetch origin
16git merge origin/main # or rebase
17
18# 5. Push feature branch
19git push -u origin feature/user-authentication
20
21# 6. Create Pull Request (on GitHub/GitLab)
22# 7. Code review happens
23# 8. Merge into main (via PR)
24# 9. Delete feature branch
25git branch -d feature/user-authenticationVisual Representation:
1main ────●────●────●──────────●────●
2 \ /
3feature ●────●────●────●
4 └── work on feature ──┘Benefits:
Best Practices:
feature/add-shopping-cartGitflow is a more structured workflow designed for projects with scheduled releases. It was introduced by Vincent Driessen in 2010.
Branch Types:
| Branch | Purpose | Lifespan |
|--------|---------|----------|
| main | Production code | Permanent |
| develop | Integration branch | Permanent |
| feature/* | New features | Temporary |
| release/* | Release preparation | Temporary |
| hotfix/* | Production fixes | Temporary |
The Complete Workflow:
1main ─────●──────────────────────●───────●
2 │ │ │
3 │ ┌─────────────────── ● │ (hotfix)
4 │ │ │ │
5develop ─────●─│────●────●────●─────●───────●
6 │ │ │ │ │
7feature/A └─●────● │ │
8 │ │
9feature/B ●────●────●───┘ │
10 │
11release/1.0 ●────●────●─────┘Working with Gitflow:
1# Initialize Gitflow (optional git-flow extension)
2git flow init
3
4# Start a feature
5git flow feature start user-profile
6# or manually:
7git switch develop
8git switch -c feature/user-profile
9
10# Finish a feature (merges into develop)
11git flow feature finish user-profile
12# or manually:
13git switch develop
14git merge feature/user-profile
15git branch -d feature/user-profile
16
17# Start a release
18git flow release start 1.0.0
19# or manually:
20git switch develop
21git switch -c release/1.0.0
22
23# Finish a release (merges to both main and develop)
24git flow release finish 1.0.0
25# or manually:
26git switch main
27git merge release/1.0.0
28git tag -a v1.0.0 -m "Version 1.0.0"
29git switch develop
30git merge release/1.0.0
31git branch -d release/1.0.0
32
33# Hotfix (urgent production fix)
34git flow hotfix start critical-bug
35# or manually:
36git switch main
37git switch -c hotfix/critical-bug
38# ... fix the bug ...
39git switch main
40git merge hotfix/critical-bug
41git tag -a v1.0.1 -m "Hotfix"
42git switch develop
43git merge hotfix/critical-bug
44git branch -d hotfix/critical-bugWhen to Use Gitflow:
GitHub Flow is a simpler alternative to Gitflow, designed for continuous deployment.
Core Principles:
The Process:
1# 1. Create a branch from main
2git switch main
3git pull origin main
4git switch -c fix-navigation-bug
5
6# 2. Make commits
7git add .
8git commit -m "Fix navigation alignment issue"
9git commit -m "Add responsive breakpoint"
10
11# 3. Push and create Pull Request
12git push -u origin fix-navigation-bug
13# Create PR on GitHub with description
14
15# 4. Discuss and review
16# - Teammates comment on PR
17# - CI/CD runs tests
18# - Deploy to staging for testing
19
20# 5. Merge to main
21# (Usually done via GitHub UI after approval)
22
23# 6. Deploy
24# (Automatic in most CI/CD setups)Visual Representation:
1main ────●────●────●────●────●────●
2 \ / \ /
3 ●─────● ●────●
4 fix-bug new-feature
5
6 PR → Review → Merge → DeployGitHub Flow Rules:
Comparison with Gitflow:
| Aspect | GitHub Flow | Gitflow |
|--------|-------------|---------|
| Complexity | Simple | Complex |
| Branches | 2 (main + feature) | 5+ types |
| Releases | Continuous | Scheduled |
| Best for | Web apps, SaaS | Desktop, mobile, versioned |
| Learning curve | Low | High |
Trunk-Based Development (TBD) is an even simpler workflow where developers collaborate on a single branch (trunk/main).
Core Principles:
Small Team Approach:
1# Developers commit directly to main
2git switch main
3git pull origin main
4# Make small, incremental change
5git add .
6git commit -m "Add email validation"
7git push origin mainScaled Approach (Short-Lived Branches):
1# Create branch, but merge same day
2git switch main
3git pull origin main
4git switch -c small-fix
5
6# Work for a few hours max
7git add .
8git commit -m "Fix email regex"
9
10# Merge back quickly
11git switch main
12git pull origin main
13git merge small-fix
14git push origin main
15git branch -d small-fixFeature Flags:
1// Hide incomplete features
2if (featureFlags.newDashboard) {
3 showNewDashboard();
4} else {
5 showOldDashboard();
6}When to Use TBD:
Comparison:
1Feature Branch: main ─────●──────────●─────
2 \ /
3 ●──●──●
4 (days/weeks)
5
6Trunk-Based: main ─●──●──●──●──●──●──●──
7 │ │ │ │ │ │ │
8 direct commits or same-day mergesDifferent projects and teams need different workflows. Here's how to choose.
Decision Matrix:
| Factor | Feature Branch | Gitflow | GitHub Flow | Trunk-Based |
|--------|----------------|---------|-------------|-------------|
| Team Size | Any | Large | Small-Medium | Small |
| Release Schedule | Flexible | Scheduled | Continuous | Continuous |
| Environments | Few | Many | Few | Few |
| CI/CD Maturity | Basic | Any | Required | Required |
| Code Review | PR-based | PR-based | PR-based | Optional |
Choose Feature Branch When:
Choose Gitflow When:
Choose GitHub Flow When:
Choose Trunk-Based When:
Real-World Examples:
| Company | Workflow | Why |
|---------|----------|-----|
| Facebook | Trunk-Based | Continuous deployment |
| Google | Trunk-Based | Monorepo, feature flags |
| GitLab | GitHub Flow variant | Continuous delivery |
| Open Source | Feature Branch | Community PRs |
Hybrid Approaches:
Many teams adapt workflows:
1GitHub Flow + Release Tags:
2
3main ────●────●────●────●────●
4 │ │
5 v1.0.0 v1.1.0
6
7(No release branches, just tags)Starting Recommendation:
The key is consistency - whatever workflow you choose, make sure everyone follows it.
See how different workflows organize branches and releases. Toggle between workflows to understand their structures.
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="UTF-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>Git Workflow Comparison</title>
7 <style>
8 body {
9 font-family: 'Segoe UI', system-ui, sans-serif;
10 background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
11 min-height: 100vh;
12 color: #e0e0e0;
13 padding: 20px;
14 }
15 .container { max-width: 1000px; margin: 0 auto; }
16 h1 { text-align: center; color: #f97316; margin-bottom: 10px; }
17 .subtitle { text-align: center; color: #9ca3af; margin-bottom: 25px; }
18
19 .workflow-tabs {
20 display: flex;
21 justify-content: center;
22 gap: 10px;
23 margin-bottom: 25px;
24 flex-wrap: wrap;
25 }
26
27 .tab-btn {
28 padding: 12px 24px;
29 border: 2px solid rgba(255, 255, 255, 0.1);
30 border-radius: 8px;
31 background: rgba(255, 255, 255, 0.03);
32 color: #e0e0e0;
33 cursor: pointer;
34 font-weight: 500;
35 transition: all 0.3s;
36 }
37
38 .tab-btn:hover {
39 border-color: #f97316;
40 background: rgba(249, 115, 22, 0.1);
41 }
42
43 .tab-btn.active {
44 border-color: #f97316;
45 background: #f97316;
46 color: white;
47 }
48
49 .workflow-view {
50 background: rgba(255, 255, 255, 0.03);
51 border-radius: 12px;
52 padding: 25px;
53 margin-bottom: 20px;
54 }
55
56 .workflow-header {
57 display: flex;
58 justify-content: space-between;
59 align-items: center;
60 margin-bottom: 20px;
61 }
62
63 .workflow-title {
64 color: #f97316;
65 font-size: 1.3rem;
66 }
67
68 .complexity-badge {
69 padding: 5px 15px;
70 border-radius: 20px;
71 font-size: 13px;
72 font-weight: 600;
73 }
74
75 .complexity-simple { background: #22c55e; color: white; }
76 .complexity-moderate { background: #eab308; color: black; }
77 .complexity-complex { background: #ef4444; color: white; }
78
79 .branch-diagram {
80 background: rgba(0, 0, 0, 0.3);
81 border-radius: 10px;
82 padding: 25px;
83 overflow-x: auto;
84 margin-bottom: 20px;
85 }
86
87 .branch-line {
88 display: flex;
89 align-items: center;
90 margin-bottom: 20px;
91 }
92
93 .branch-name {
94 width: 100px;
95 padding: 6px 12px;
96 border-radius: 6px;
97 font-size: 12px;
98 font-weight: 600;
99 text-align: center;
100 margin-right: 15px;
101 }
102
103 .branch-main { background: #22c55e; color: white; }
104 .branch-develop { background: #3b82f6; color: white; }
105 .branch-feature { background: #a855f7; color: white; }
106 .branch-release { background: #eab308; color: black; }
107 .branch-hotfix { background: #ef4444; color: white; }
108
109 .commits {
110 display: flex;
111 align-items: center;
112 gap: 10px;
113 }
114
115 .commit {
116 width: 30px;
117 height: 30px;
118 border-radius: 50%;
119 display: flex;
120 align-items: center;
121 justify-content: center;
122 font-size: 10px;
123 font-weight: bold;
124 color: white;
125 }
126
127 .tag {
128 background: #fbbf24;
129 color: #1a1a2e;
130 padding: 2px 8px;
131 border-radius: 4px;
132 font-size: 10px;
133 font-weight: bold;
134 margin-left: 5px;
135 }
136
137 .connector {
138 width: 30px;
139 height: 2px;
140 background: #4b5563;
141 }
142
143 .merge-line {
144 position: relative;
145 }
146
147 .workflow-info {
148 display: grid;
149 grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
150 gap: 15px;
151 }
152
153 .info-card {
154 background: rgba(255, 255, 255, 0.03);
155 border-radius: 8px;
156 padding: 15px;
157 }
158
159 .info-card h4 {
160 color: #60a5fa;
161 margin-bottom: 10px;
162 font-size: 14px;
163 }
164
165 .info-card ul {
166 list-style: none;
167 font-size: 13px;
168 color: #9ca3af;
169 }
170
171 .info-card li {
172 padding: 4px 0;
173 }
174
175 .info-card li::before {
176 content: "•";
177 color: #f97316;
178 margin-right: 8px;
179 }
180
181 .best-for {
182 background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(34, 197, 94, 0.05));
183 border: 1px solid rgba(34, 197, 94, 0.3);
184 border-radius: 10px;
185 padding: 15px;
186 margin-top: 20px;
187 }
188
189 .best-for h4 {
190 color: #22c55e;
191 margin-bottom: 10px;
192 }
193
194 .best-for p {
195 color: #a7f3d0;
196 font-size: 14px;
197 }
198 </style>
199</head>
200<body>
201 <div class="container">
202 <h1>Git Workflow Comparison</h1>
203 <p class="subtitle">Compare different branching strategies</p>
204
205 <div class="workflow-tabs">
206 <button class="tab-btn active" onclick="showWorkflow('feature')">Feature Branch</button>
207 <button class="tab-btn" onclick="showWorkflow('gitflow')">Gitflow</button>
208 <button class="tab-btn" onclick="showWorkflow('github')">GitHub Flow</button>
209 <button class="tab-btn" onclick="showWorkflow('trunk')">Trunk-Based</button>
210 </div>
211
212 <div class="workflow-view" id="workflow-content"></div>
213 </div>
214
215 <script>
216 const workflows = {
217 feature: {
218 title: 'Feature Branch Workflow',
219 complexity: 'simple',
220 branches: [
221 { name: 'main', type: 'main', commits: ['●', '●', '●', '●', '●', '●'] },
222 { name: 'feature/A', type: 'feature', commits: ['●', '●', '●'] },
223 { name: 'feature/B', type: 'feature', commits: ['●', '●'] }
224 ],
225 pros: ['Simple to understand', 'Easy to adopt', 'Good for PRs', 'Works with any team size'],
226 cons: ['No structured releases', 'Main can get busy', 'Need good communication'],
227 bestFor: 'Most web applications and teams new to Git workflows. Perfect starting point.'
228 },
229 gitflow: {
230 title: 'Gitflow Workflow',
231 complexity: 'complex',
232 branches: [
233 { name: 'main', type: 'main', commits: ['●', '●', 'v1.0'] },
234 { name: 'develop', type: 'develop', commits: ['●', '●', '●', '●', '●'] },
235 { name: 'feature/X', type: 'feature', commits: ['●', '●'] },
236 { name: 'release/1.0', type: 'release', commits: ['●', '●'] },
237 { name: 'hotfix/bug', type: 'hotfix', commits: ['●'] }
238 ],
239 pros: ['Structured releases', 'Parallel development', 'Good for versioned software', 'Clear process'],
240 cons: ['Complex to learn', 'Many branches', 'Overhead for small teams', 'Slower releases'],
241 bestFor: 'Desktop apps, mobile apps, and projects with scheduled releases and multiple versions.'
242 },
243 github: {
244 title: 'GitHub Flow',
245 complexity: 'simple',
246 branches: [
247 { name: 'main', type: 'main', commits: ['●', '●', '●', '●', '●'] },
248 { name: 'fix-bug', type: 'feature', commits: ['●', '●'] },
249 { name: 'new-feature', type: 'feature', commits: ['●'] }
250 ],
251 pros: ['Very simple', 'Continuous deployment', 'Fast iteration', 'Great for CI/CD'],
252 cons: ['No release branches', 'Less structure', 'Requires good CI/CD'],
253 bestFor: 'SaaS products, web apps, and teams practicing continuous deployment.'
254 },
255 trunk: {
256 title: 'Trunk-Based Development',
257 complexity: 'moderate',
258 branches: [
259 { name: 'main', type: 'main', commits: ['●', '●', '●', '●', '●', '●', '●', '●'] }
260 ],
261 pros: ['Maximum simplicity', 'Fast integration', 'No merge debt', 'Best for CI/CD'],
262 cons: ['Requires discipline', 'Need feature flags', 'High test coverage needed'],
263 bestFor: 'High-performing teams with excellent CI/CD and test coverage.'
264 }
265 };
266
267 function showWorkflow(type) {
268 const workflow = workflows[type];
269
270 document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
271 event.target.classList.add('active');
272
273 let branchesHTML = workflow.branches.map(branch => {
274 const commits = branch.commits.map(c => {
275 if (c.startsWith('v')) {
276 return '<span class="tag">' + c + '</span>';
277 }
278 return '<div class="commit branch-' + branch.type + '">' + c + '</div><div class="connector"></div>';
279 }).join('');
280
281 return '<div class="branch-line"><div class="branch-name branch-' + branch.type + '">' + branch.name + '</div><div class="commits">' + commits + '</div></div>';
282 }).join('');
283
284 const complexityClass = 'complexity-' + workflow.complexity;
285
286 document.getElementById('workflow-content').innerHTML =
287 '<div class="workflow-header">' +
288 '<h2 class="workflow-title">' + workflow.title + '</h2>' +
289 '<span class="complexity-badge ' + complexityClass + '">' + workflow.complexity.toUpperCase() + '</span>' +
290 '</div>' +
291 '<div class="branch-diagram">' + branchesHTML + '</div>' +
292 '<div class="workflow-info">' +
293 '<div class="info-card"><h4>Advantages</h4><ul>' + workflow.pros.map(p => '<li>' + p + '</li>').join('') + '</ul></div>' +
294 '<div class="info-card"><h4>Challenges</h4><ul>' + workflow.cons.map(c => '<li>' + c + '</li>').join('') + '</ul></div>' +
295 '</div>' +
296 '<div class="best-for"><h4>Best For</h4><p>' + workflow.bestFor + '</p></div>';
297 }
298
299 // Initialize
300 showWorkflow('feature');
301 </script>
302</body>
303</html>This comparison tool helps you understand the different Git workflows:
Feature Branch Workflow:
Gitflow:
GitHub Flow:
Trunk-Based:
Choose based on your team size, release schedule, and CI/CD maturity.
You now understand professional Git workflows! In the next lesson, we'll explore rebasing and history management - powerful techniques for keeping your Git history clean and organized. You'll learn when to rebase vs merge and how to rewrite history safely.
Your progress is saved in this browser, on this device only.