-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitflow.html
More file actions
1330 lines (1151 loc) · 62.8 KB
/
Copy pathgitflow.html
File metadata and controls
1330 lines (1151 loc) · 62.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="vi">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitFlow: Quy Trình Quản Lý Mã Nguồn Hiệu Quả - Blog của Bechovang</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<div class="container header-content">
<a href="index.html" class="logo">
<svg width="24" height="24" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z" fill="white"/>
</svg>
Blog của Bechovang
</a>
<nav>
<ul>
<li><a href="index.html">Trang chủ</a></li>
<li><a href="TakeNote.html">Ghi Chú AI & Obsidian</a></li>
<li><a href="gitflow.html">GitFlow</a></li>
<li><a href="#">Liên hệ</a></li>
</ul>
</nav>
</div>
</header>
<main class="container">
<article class="blog-content">
<div class="blog-header">
<h1 class="blog-title">GitFlow: Quy Trình Quản Lý Mã Nguồn Hiệu Quả Cho Dự Án Phần Mềm</h1>
<div class="blog-info">
<div class="blog-date">
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M4.5 1H3v2h1.5V1zm8 0H11v2h1.5V1zM11 14h1v-2.5h-1V14zm-7 0h1v-2.5H4V14zm-1-7h10V5.5H3V7zm9 5.5v-4.5H9.5V9H7v3.5H8v-2h1v2h3zm-8 0v-4.5h3V9H8v1H7v2.5H4zm0-10V4h8V2.5H4z"/>
</svg>
2026-04-09
</div>
<div class="blog-tags">
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M2 3.75C2 2.784 2.784 2 3.75 2h5.5c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0 1 9.25 14h-5.5A1.75 1.75 0 0 1 2 12.25v-8.5zm1.75-.25a.25.25 0 0 0-.25.25v8.5c0 .138.112.25.25.25h5.5a.25.25 0 0 0 .25-.25v-8.5a.25.25 0 0 0-.25-.25h-5.5zM6 7a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/>
</svg>
<a href="#" class="tag">Git</a>
<a href="#" class="tag">DevOps</a>
<a href="#" class="tag">Workflow</a>
</div>
</div>
</div>
<h2>Mở đầu</h2>
<p>Trong thế giới phát triển phần mềm hiện đại, <strong>Git</strong> đã trở thành công cụ quản lý mã nguồn không thể thiếu. Tuy nhiên, việc chỉ sử dụng Git là chưa đủ - để làm việc nhóm hiệu quả, tránh xung đột mã nguồn và duy trì chất lượng dự án, chúng ta cần một quy trình làm việc rõ ràng.</p>
<p><strong>GitFlow</strong> là một trong những workflow nổi tiếng nhất, được giới thiệu bởi Vincent Driessen vào năm 2010. Nó cung cấp một mô hình phân nhánh có cấu trúc chặt chẽ, giúp các đội phát triển quản lý mã nguồn một cách có tổ chức và hiệu quả.</p>
<blockquote>
<p><em>"GitFlow không chỉ là một quy trình - đó là một tư duy về cách tổ chức công việc phát triển phần mềm một cách có hệ thống."</em></p>
</blockquote>
<img src="images/bai3/gitflow-intro.png" alt="Giới thiệu GitFlow">
<p><em>Bài viết này sẽ hướng dẫn bạn từ khái niệm cơ bản đến thực hành GitFlow, kèm theo ví dụ minh họa và so sánh với các workflow khác.</em></p>
<hr class="hr-short-subtle">
<h2>Phần 1: Kiến Thức Cơ Bản</h2>
<h3>1.1 Git Workflow là gì?</h3>
<p><strong>Git Workflow</strong> là một quy trình làm việc hoặc phương pháp tổ chức việc sử dụng Git trong quản lý mã nguồn. Nó bao gồm các quy định về:</p>
<ul>
<li><strong>Cách tổ chức nhánh:</strong> Quy định đặt tên, tạo và sử dụng nhánh như main, develop, feature, hotfix, release...</li>
<li><strong>Quy trình tách và hợp nhất nhánh:</strong> Ví dụ nhánh feature phải tách từ develop, mã từ develop mới được phép merge vào main</li>
<li><strong>Quy tắc cộng tác:</strong> Quy định về Pull Request, code review trước khi merge...</li>
</ul>
<h3>1.2 Tại sao cần Git Workflow?</h3>
<h4>Vấn đề khi không có quy trình rõ ràng</h4>
<p>Khi làm việc nhóm mà không có workflow, các vấn đề thường gặp phải:</p>
<ul>
<li><strong>Xung đột mã nguồn (Merge Conflicts):</strong> Nhiều người cùng modify code ở cùng file</li>
<li><strong>Mất kiểm soát phiên bản:</strong> Không biết code nào đang ở production, code nào đang phát triển</li>
<li><strong>Khó khăn trong việc rollback:</strong> Khi có bug ở production, khó xác định version nào để rollback</li>
<li><strong>Thiếu quy trình review:</strong> Code được merge mà không có người kiểm tra chất lượng</li>
</ul>
<h4>Giải pháp từ Git Workflow</h4>
<img src="images/bai3/workflow-problems.png" alt="Vấn đề workflow và giải pháp">
<p>Git Workflow giúp:</p>
<ul>
<li>✅ Tránh xung đột khi hợp nhất</li>
<li>✅ Giữ mã nguồn production luôn sạch sẽ</li>
<li>✅ Cộng tác suôn sẻ với các thành viên trong nhóm</li>
<li>✅ Theo dõi và review thay đổi hiệu quả</li>
</ul>
<h3>1.3 GitFlow là gì?</h3>
<p><strong>GitFlow</strong> là một mô hình phân nhánh Git được thiết kế đặc biệt cho các dự án có chu kỳ phát hành định kỳ. Mô hình này sử dụng các nhánh tính năng (feature branch) và nhiều nhánh chính (primary branch) với vai trò cụ thể.</p>
<p><strong>Lịch sử ngắn gọn:</strong></p>
<ul>
<li><strong>2010:</strong> Vincent Driessen giới thiệu GitFlow trong bài viết "A successful Git branching model"</li>
<li><strong>2010-2020:</strong> GitFlow trở thành standard cho nhiều enterprise projects</li>
<li><strong>2020-nay:</strong> Vincent Driessen lưu ý GitFlow có thể không phù hợp cho continuous delivery, khuyến dùng GitHub Flow cho các dự án web app</li>
</ul>
<hr class="hr-short-subtle">
<h2>Phần 2: Cấu Trúc Chi Tiết Của GitFlow</h2>
<h3>2.1 Các nhánh chính (Main Branches)</h3>
<p>GitFlow sử dụng hai nhánh chính với vòng đời vô hạn:</p>
<img src="images/bai3/main-branches.png" alt="Các nhánh chính trong GitFlow">
<h4>2.1.1 Nhánh Master (hoặc Main)</h4>
<div class="code-block-container">
<pre><code>origin/master
├── Chứa code production-ready
├── Mỗi commit là một phiên bản release
└── Được đánh tag với version number</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Vai trò:</strong></p>
<ul>
<li>Lưu trữ lịch sử phát hành chính thức</li>
<li>Luôn ở trạng thái ổn định, có thể deploy</li>
<li>Mỗi lần merge vào master = một phiên bản mới</li>
</ul>
<h4>2.1.2 Nhánh Develop</h4>
<div class="code-block-container">
<pre><code>origin/develop
├── Chứa code đang phát triển
├── Nơi tích hợp các feature hoàn thành
└── Dùng cho nightly builds</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Vai trò:</strong></p>
<ul>
<li>Là nhánh tích hợp (integration branch)</li>
<li>Chứa các tính năng sắp phát hành</li>
<li>Nền tảng cho việc tạo feature branches</li>
</ul>
<h3>2.2 Các nhánh phụ (Supporting Branches)</h3>
<p>Ngoài hai nhánh chính, GitFlow sử dụng các nhánh phụ với vòng đời giới hạn:</p>
<h4>2.2.1 Feature Branches</h4>
<img src="images/bai3/feature-branches.png" alt="Feature Branches trong GitFlow">
<p><strong>Đặc điểm:</strong></p>
<ul>
<li><strong>Tách từ:</strong> develop</li>
<li><strong>Hợp nhất vào:</strong> develop</li>
<li><strong>Quy tắc đặt tên:</strong> <code>feature/</code> hoặc bất kỳ tên nào trừ master, develop, release-*, hotfix-*</li>
</ul>
<p><strong>Mục đích:</strong></p>
<ul>
<li>Phát triển tính năng mới</li>
<li>Cô lập code để không ảnh hưởng develop</li>
<li>Cho phép review code trước khi merge</li>
</ul>
<p><strong>Ví dụ lệnh:</strong></p>
<div class="code-block-container">
<pre><code># Tạo feature branch
git checkout develop
git checkout -b feature/user-authentication
# Hoàn thành feature
git checkout develop
git merge --no-ff feature/user-authentication
git branch -d feature/user-authentication
git push origin develop</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>2.2.2 Release Branches</h4>
<img src="images/bai3/release-branches.png" alt="Release Branches trong GitFlow">
<p><strong>Đặc điểm:</strong></p>
<ul>
<li><strong>Tách từ:</strong> develop</li>
<li><strong>Hợp nhất vào:</strong> develop VÀ master</li>
<li><strong>Quy tắc đặt tên:</strong> <code>release-*</code></li>
</ul>
<p><strong>Mục đích:</strong></p>
<ul>
<li>Chuẩn bị cho release mới</li>
<li>Fix bug nhỏ trước release</li>
<li>Update metadata (version number, build dates)</li>
<li>Không thêm feature mới</li>
</ul>
<p><strong>Quy trình:</strong></p>
<div class="code-block-container">
<pre><code># Bắt đầu release
git checkout develop
git checkout -b release-1.2.0
# Bump version
# (Edit files to reflect new version)
# Hoàn thành release
git checkout master
git merge --no-ff release-1.2.0
git tag -a 1.2.0 -m "Release version 1.2.0"
git checkout develop
git merge --no-ff release-1.2.0
git branch -d release-1.2.0</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>2.2.3 Hotfix Branches</h4>
<img src="images/bai3/hotfix-branches.png" alt="Hotfix Branches trong GitFlow">
<p><strong>Đặc điểm:</strong></p>
<ul>
<li><strong>Tách từ:</strong> master</li>
<li><strong>Hợp nhất vào:</strong> develop VÀ master</li>
<li><strong>Quy tắc đặt tên:</strong> <code>hotfix-*</code></li>
</ul>
<p><strong>Mục đích:</strong></p>
<ul>
<li>Sửa lỗi khẩn cấp ở production</li>
<li>Không làm gián đoạn workflow hiện tại</li>
<li>Cho phép fix nhanh mà không cần tạo release branch</li>
</ul>
<p><strong>Quy trình:</strong></p>
<div class="code-block-container">
<pre><code># Bắt đầu hotfix
git checkout master
git checkout -b hotfix-1.2.1
# Fix the bug...
git commit -m "Fix critical bug in production"
# Hoàn thành hotfix
git checkout master
git merge --no-ff hotfix-1.2.1
git tag -a 1.2.1 -m "Hotfix version 1.2.1"
git checkout develop
git merge --no-ff hotfix-1.2.1
git branch -d hotfix-1.2.1</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>2.3 Sơ đồ tổng quan GitFlow</h3>
<img src="images/bai3/gitflow-overview.png" alt="Sơ đồ tổng quan GitFlow">
<p>Sơ đồ trên cho thấy:</p>
<ul>
<li><strong>master:</strong> Nhánh chính cho production</li>
<li><strong>develop:</strong> Nhánh tích hợp features</li>
<li><strong>feature*:</strong> Các nhánh phát triển tính năng</li>
<li><strong>release*:</strong> Các nhánh chuẩn bị release</li>
<li><strong>hotfix*:</strong> Các nhánh sửa lỗi khẩn cấp</li>
</ul>
<hr class="hr-short-subtle">
<h2>Phần 3: Quy Trình Chi Tiết</h2>
<h3>3.1 Workflow hoàn chỉnh</h3>
<h4>Bước 1: Khởi tạo dự án</h4>
<div class="code-block-container">
<pre><code># Clone repository
git clone <repository-url>
cd <project-name>
# Tạo develop branch
git branch develop
git push -u origin develop
# Hoặc sử dụng git-flow extension
git flow init</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Cấu hình git-flow:</strong></p>
<div class="code-block-container">
<pre><code>Branch name for production releases: [master]
Branch name for "next release" development: [develop]
Feature branches? [feature/]
Release branches? [release/]
Hotfix branches? [hotfix/]
Support branches? [support/]
Version tag prefix? []</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>Bước 2: Phát triển tính năng (Feature Development)</h4>
<div class="code-block-container">
<pre><code># Bắt đầu feature
git flow feature start user-login
# Làm việc trên feature...
# Viết code, test, commit...
# Hoàn thành feature
git flow feature finish user-login</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Quy trình chi tiết:</strong></p>
<ol>
<li>Tách feature branch từ develop</li>
<li>Phát triển tính năng độc lập</li>
<li>Tạo Pull Request để review</li>
<li>Merge vào develop sau khi được approve</li>
<li>Xóa feature branch</li>
</ol>
<h4>Bước 3: Chuẩn bị release</h4>
<div class="code-block-container">
<pre><code># Khi develop đã đủ features cho một release
git flow release start 1.0.0
# Testing, fix bugs, bump version...
# Hoàn thành release
git flow release finish 1.0.0</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Các công việc trên release branch:</strong></p>
<ul>
<li>Fix bug nhỏ</li>
<li>Update version number</li>
<li>Update changelog</li>
<li>Prepare release notes</li>
<li>Final testing</li>
</ul>
<h4>Bước 4: Sửa lỗi khẩn cấp (Hotfix)</h4>
<div class="code-block-container">
<pre><code># Có bug critical ở production
git flow hotfix start critical-bug-1.0.1
# Fix bug...
# Deploy fix ngay lập tức
git flow hotfix finish critical-bug-1.0.1</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>3.2 Quy tắc quan trọng</h3>
<table>
<thead>
<tr>
<th>Quy tắc</th>
<th>Mô tả</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Quy tắc 1</strong></td>
<td>Feature branch KHÔNG BAO GIỜ merge trực tiếp vào master</td>
</tr>
<tr>
<td><strong>Quy tắc 2</strong></td>
<td>Tất cả changes phải đi qua develop trước khi vào master</td>
</tr>
<tr>
<td><strong>Quy tắc 3</strong></td>
<td>Hotfix branch là NHẤT nhánh được tách trực tiếp từ master</td>
</tr>
<tr>
<td><strong>Quy tắc 4</strong></td>
<td>Release branch phải merge vào CẢ master VÀ develop</td>
</tr>
<tr>
<td><strong>Quy tắc 5</strong></td>
<td>Luôn dùng flag <code>--no-ff</code> khi merge để preserve history</td>
</tr>
</tbody>
</table>
<hr class="hr-short-subtle">
<h2>Phần 4: So Sánh Với Workflow Khác</h2>
<h3>4.1 Bảng so sánh chi tiết</h3>
<table>
<thead>
<tr>
<th>Tiêu chí</th>
<th>Centralized</th>
<th>GitHub Flow</th>
<th>Feature Branch</th>
<th><strong>Gitflow</strong></th>
<th>Forking</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Cấu trúc</strong></td>
<td>Chỉ main</td>
<td>main + feature</td>
<td>main + develop + feature</td>
<td><strong>main + develop + feature + release + hotfix</strong></td>
<td>Mỗi người có kho riêng</td>
</tr>
<tr>
<td><strong>Độ phức tạp</strong></td>
<td>Cực kỳ đơn giản</td>
<td>Đơn giản</td>
<td>Phức tạp vừa phải</td>
<td><strong>Phức tạp nhất</strong></td>
<td>Phức tạp khi nhiều PR</td>
</tr>
<tr>
<td><strong>Mức độ kiểm soát</strong></td>
<td>Thấp</td>
<td>Trung bình</td>
<td>Cao</td>
<td><strong>Rất cao</strong></td>
<td>Cao</td>
</tr>
<tr>
<td><strong>CI/CD</strong></td>
<td>Hạn chế</td>
<td>Tốt</td>
<td>Tốt</td>
<td><strong>Tốt cho dự án dài hạn</strong></td>
<td>Tùy vào PR</td>
</tr>
<tr>
<td><strong>Xung đột mã</strong></td>
<td>Cao</td>
<td>Thấp</td>
<td>Thấp</td>
<td><strong>Trung bình</strong></td>
<td>Thấp</td>
</tr>
<tr>
<td><strong>Chu kỳ phát hành</strong></td>
<td>Không có</td>
<td>Không có</td>
<td>Cần thêm quy trình</td>
<td><strong>Có chu kỳ rõ ràng</strong></td>
<td>Không phù hợp</td>
</tr>
<tr>
<td><strong>Phù hợp nhất</strong></td>
<td>Dự án cá nhân</td>
<td>Dự án nhỏ, CD</td>
<td>Dự án vừa-lớn</td>
<td><strong>Dự án lớn, có release cycle</strong></td>
<td>Open source</td>
</tr>
</tbody>
</table>
<h3>4.2 Khi nào nên dùng GitFlow?</h3>
<p><strong>Nên dùng GitFlow khi:</strong></p>
<ul>
<li>✅ Dự án có <strong>chu kỳ phát hành định kỳ</strong> (tháng, quý)</li>
<li>✅ Cần <strong>hỗ trợ nhiều phiên bản</strong> song song</li>
<li>✅ Dự án <strong>lớn</strong> với nhiều developers</li>
<li>✅ Cần <strong>quy trình chặt chẽ</strong> cho release management</li>
<li>✅ Có <strong>team riêng</strong> cho QA và release preparation</li>
</ul>
<p><strong>KHÔNG nên dùng GitFlow khi:</strong></p>
<ul>
<li>❌ Dự án <strong>nhỏ</strong> với 1-3 developers</li>
<li>❌ Áp dụng <strong>Continuous Delivery</strong> (deploy nhiều lần/ngày)</li>
<li>❌ Team mới làm quen với Git</li>
<li>❌ Dự án cần <strong>flexibility</strong> cao</li>
<li>❌ Web apps với <strong>continuous deployment</strong></li>
</ul>
<h3>4.3 So sánh với GitHub Flow</h3>
<img src="images/bai3/github-flow-comparison.png" alt="So sánh GitFlow và GitHub Flow">
<table>
<thead>
<tr>
<th>Đặc điểm</th>
<th>GitHub Flow</th>
<th>Gitflow</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nhánh chính</td>
<td>main</td>
<td>master + develop</td>
</tr>
<tr>
<td>Feature branch</td>
<td>Từ main</td>
<td>Từ develop</td>
</tr>
<tr>
<td>Release branch</td>
<td>Không có</td>
<td>Có</td>
</tr>
<tr>
<td>Hotfix branch</td>
<td>Từ main (feature)</td>
<td>Từ master (dedicated)</td>
</tr>
<tr>
<td>Deployment</td>
<td>Từ main</td>
<td>Từ master (tagged)</td>
</tr>
<tr>
<td>Versioning</td>
<td>Không bắt buộc</td>
<td>Bắt buộc (tags)</td>
</tr>
</tbody>
</table>
<hr class="hr-short-subtle">
<h2>Phần 5: Thực Hành Và Ví Dụ</h2>
<h3>5.1 Ví dụ thực tế: Dự án E-commerce</h3>
<h4>Bối cảnh</h4>
<ul>
<li>Dự án: E-commerce website</li>
<li>Team: 5 developers</li>
<li>Release cycle: 2 tuần/lần</li>
<li>Yêu cầu: Support multiple versions in production</li>
</ul>
<h4>Kịch bản 1: Thêm tính năng Cart</h4>
<div class="code-block-container">
<pre><code># Day 1: Developer A bắt đầu feature Cart
git flow feature start shopping-cart
# Day 1-5: Developer A làm việc trên feature
# (Commits, test, local development)
# Day 5: Hoàn thành feature
git flow feature finish shopping-cart
# Kết quả: Code được merge vào develop
# Team khác có thể thấy và review</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>Kịch bản 2: Chuẩn bị Release 1.2</h4>
<div class="code-block-container">
<pre><code># Day 10: Develop đủ features cho release 1.2
git flow release start 1.2.0
# Day 10-12: Team QA test trên release branch
# Fix bugs phát hiện
# Update version number
# Day 12: Deploy to production
git flow release finish 1.2.0
git push origin master
git push origin develop
git push --tags</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>Kịch bản 3: Hotfix bug critical</h4>
<div class="code-block-container">
<pre><code># Day 15: Có bug critical ở production 1.2.0
git flow hotfix start payment-crash-1.2.1
# Fix ngay lập tức
# Test locally
# Deploy to staging
# Hoàn thành hotfix
git flow hotfix finish payment-crash-1.2.1
# Deploy to production immediately</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>5.2 Demo: Thiết lập GitFlow từ con số 0</h3>
<h4>Bước 1: Cài đặt git-flow</h4>
<p><strong>Mac:</strong></p>
<div class="code-block-container">
<pre><code>brew install git-flow-avh</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Linux (Ubuntu/Debian):</strong></p>
<div class="code-block-container">
<pre><code>sudo apt-get install git-flow</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<p><strong>Windows:</strong></p>
<div class="code-block-container">
<pre><code># Sử dụng Git for Windows hoặc WSL
# git-flow thường đã được tích hợp</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>Bước 2: Khởi tạo dự án mới</h4>
<div class="code-block-container">
<pre><code># Tạo repository mới
mkdir my-project
cd my-project
git init
# Commit khởi tạo
echo "# My Project" > README.md
git add README.md
git commit -m "Initial commit"
# Khởi tạo git-flow
git flow init
# Cấu hình như hướng dẫn ở phần 3.1</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>Bước 3: Tạo feature đầu tiên</h4>
<div class="code-block-container">
<pre><code># Bắt đầu feature
git flow feature start hello-world
# Sửa code
echo "console.log('Hello World!');" > app.js
git add app.js
git commit -m "Add hello world functionality"
# Hoàn thành feature
git flow feature finish hello-world
# Kết quả: Code đã ở develop</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>5.3 Git Flow AVH Extension</h3>
<p><strong>Git Flow AVH</strong> là bộ mở rộng Git giúp làm việc với GitFlow dễ dàng hơn:</p>
<table>
<thead>
<tr>
<th>Lệnh</th>
<th>Mô tả</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>git flow init</code></td>
<td>Khởi tạo git-flow</td>
</tr>
<tr>
<td><code>git flow feature start NAME</code></td>
<td>Bắt đầu feature</td>
</tr>
<tr>
<td><code>git flow feature finish NAME</code></td>
<td>Hoàn thành feature</td>
</tr>
<tr>
<td><code>git flow release start VERSION</code></td>
<td>Bắt đầu release</td>
</tr>
<tr>
<td><code>git flow release finish VERSION</code></td>
<td>Hoàn thành release</td>
</tr>
<tr>
<td><code>git flow hotfix start VERSION</code></td>
<td>Bắt đầu hotfix</td>
</tr>
<tr>
<td><code>git flow hotfix finish VERSION</code></td>
<td>Hoàn thành hotfix</td>
</tr>
</tbody>
</table>
<hr class="hr-short-subtle">
<h2>Phần 6: Kiến Thức Mở Rộng</h2>
<h3>6.1 Lưu ý quan trọng từ Vincent Driessen (2020)</h3>
<img src="images/bai3/vincent-driessen-note.png" alt="Lưu ý từ Vincent Driessen">
<blockquote>
<p><em>"This model was conceived in 2010, now more than 10 years ago... If your team is doing continuous delivery of software, I would suggest to adopt a much simpler workflow (like GitHub Flow) instead of trying to shoehorn git-flow into your team."</em></p>
</blockquote>
<p><strong>Khi nào nên THẬN TRỌNG với GitFlow:</strong></p>
<ul>
<li>Dự án web apps với continuous delivery</li>
<li>Deploy nhiều lần/ngày</li>
<li>Không cần support multiple versions</li>
<li>Team nhỏ cần flexibility</li>
</ul>
<h3>6.2 Best Practices</h3>
<h4>6.2.1 Quy tắc đặt tên nhánh</h4>
<div class="code-block-container">
<pre><code># Tốt ✅
feature/user-authentication
feature/payment-gateway
release/v1.2.0
hotfix/critical-bug-login
# Tránh ❌
feature1
login-fix
release-1</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>6.2.2 Commit message</h4>
<div class="code-block-container">
<pre><code># Tốt ✅
feat: add user authentication
fix: resolve payment gateway timeout
docs: update API documentation
# Tránh ❌
update
fix bug
done</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h4>6.2.3 Chiến lược Merge</h4>
<div class="code-block-container">
<pre><code># Luôn dùng --no-ff để preserve history
git merge --no-ff feature/new-feature
# Điều này giữ được context của feature branch
# Giảm merge conflicts về sau</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>6.3 Tích hợp CI/CD</h3>
<img src="images/bai3/cicd-pipeline.png" alt="Tích hợp CI/CD với GitFlow">
<p><strong>GitFlow với CI/CD Pipeline:</strong></p>
<div class="code-block-container">
<pre><code># .gitlab-ci.yml example
stages:
- build
- test
- deploy
# Build on every branch
build:
stage: build
script:
- npm install
- npm run build
only:
- branches
# Test on develop and feature branches
test:
stage: test
script:
- npm run test
only:
- develop
- /^feature\/.*$/
# Deploy to staging from release branches
deploy_staging:
stage: deploy
script:
- deploy-to-staging.sh
only:
- /^release\/.*$/
# Deploy to production from master
deploy_production:
stage: deploy
script:
- deploy-to-prod.sh
only:
- master
when: manual</code></pre>
<button class="copy-btn" aria-label="Copy code snippet">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/>
<path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/>
</svg>
</button>
</div>
<h3>6.4 GitFlow vs Modern Practices</h3>
<table>
<thead>
<tr>
<th>Traditional GitFlow</th>
<th>Modern GitFlow</th>
</tr>
</thead>
<tbody>
<tr>
<td>Release branch dài ngày</td>
<td>Release branch ngắn (hours)</td>
</tr>
<tr>
<td>Manual deployment</td>
<td>Automated CI/CD</td>
</tr>
<tr>
<td>Long-lived feature branches</td>
<td>Short-lived feature branches</td>
</tr>
<tr>
<td>Tag manually</td>
<td>Tag automatically</td>
</tr>
</tbody>
</table>
<hr class="hr-short-subtle">
<h2>Phần 7: Ưu Điểm Và Nhược Điểm</h2>
<h3>7.1 Ưu điểm của GitFlow</h3>
<h4>1. Cấu trúc rõ ràng</h4>
<img src="images/bai3/clear-structure.png" alt="Cấu trúc rõ ràng của GitFlow">
<ul>
<li>Mỗi nhánh có mục đích rõ ràng</li>
<li>Dễ hiểu cho team members mới</li>
<li>Quy trình chuẩn hóa cho toàn team</li>
</ul>
<h4>2. Hỗ trợ release management</h4>
<ul>
<li>Chuẩn bị release một cách có tổ chức</li>
<li>Có môi trường staging riêng (release branch)</li>
<li>Dễ dàng rollback khi cần</li>
</ul>
<h4>3. Code quality assurance</h4>
<ul>
<li>Pull request cho tất cả features</li>
<li>Code review trước khi merge</li>
<li>Tách biệt giữa development và production</li>
</ul>
<h4>4. Parallel development</h4>
<ul>
<li>Multiple features có thể phát triển song song</li>
<li>Không chặn nhau</li>
<li>Hotfix không làm gián đoạn feature development</li>
</ul>
<h3>7.2 Nhược điểm của GitFlow</h3>
<h4>1. Độ phức tạp cao</h4>
<img src="images/bai3/complexity.png" alt="Độ phức tạp của GitFlow">
<ul>
<li>Nhiều nhánh cần quản lý</li>
<li>Quy trình merge phức tạp</li>
<li>Cần thời gian để làm quen</li>
</ul>
<h4>2. Merge conflicts tiềm ẩn</h4>
<ul>
<li>Long-lived branches dễ gây conflicts</li>
<li>Feature branches diverge từ develop</li>
<li>Cần effort để resolve</li>
</ul>
<h4>3. Không phù hợp continuous delivery</h4>
<ul>
<li>Release cycle dài</li>
<li>Không tối ưu cho deploy nhiều lần/ngày</li>