Git Flow · Team Workflow

Kịch Bản Git Flow
Trong Một Team

Từ sprint planning → feature → review → release → hotfix

main — production
develop — tích hợp
feature/* — tính năng
release/* — chuẩn bị release
hotfix/* — vá lỗi khẩn
bugfix/* — sửa lỗi thường
Sơ đồ nhánh tổng quan
main
← hotfix merge
develop
← features merge vào đây
feature/login
→ PR → develop
feature/dashboard
→ PR → develop
release/1.2.0
→ merge main + develop
hotfix/payment-bug
→ main + develop
01 · Sprint Planning & Setup
01
Tech Lead khởi tạo repository
👤 @techLead · Trước sprint
Tạo repo, khởi tạo 2 nhánh cố định maindevelop. Thiết lập branch protection rules.
git init
git checkout -b develop
# Bật branch protection trên GitHub/GitLab cho main & develop
main luôn là code đang chạy production. develop là nhánh tích hợp chung.
02
Team họp sprint, chia task
👥 Cả team · Sprint kickoff
PM chia ticket. Dev nhận task, mỗi ticket = 1 feature branch tách từ develop. Đặt tên nhánh theo convention.
# Convention: feature/[ticket-id]-[mô-tả-ngắn]
git checkout develop
git pull origin develop
git checkout -b feature/APP-101-user-login
02 · Phát Triển Tính Năng
03
Dev A code feature, commit thường xuyên
👤 @devA · feature/APP-101-user-login
Code theo atomic commit. Mỗi commit nhỏ, rõ ràng. Dùng conventional commits để tự gen changelog sau này.
git add src/auth/login.tsx
git commit -m "feat(auth): add login form component"
git commit -m "feat(auth): validate email/password fields"
git commit -m "test(auth): add unit tests for login"
Dùng prefix: feat · fix · refactor · test · docs · chore · ci
04
Sync với develop để tránh conflict lớn
👤 @devA · Mỗi ngày hoặc trước khi tạo PR
Rebase hoặc merge develop vào feature branch định kỳ. Giải quyết conflict nhỏ sớm hơn là để dồn.
git fetch origin
git rebase origin/develop
# hoặc: git merge origin/develop (nếu team dùng merge strategy)
03 · Code Review & Merge
05
Dev A tạo Pull Request vào develop
👤 @devA · Sau khi feature xong
Push branch lên remote, mở PR. Điền template: mô tả, ticket link, checklist test, screenshot nếu có UI. Assign reviewer.
git push origin feature/APP-101-user-login
# Mở PR trên GitHub: feature/APP-101-user-login → develop
# Assign: @techLead, @devB làm reviewer
PR cần pass CI (lint, test, build) trước khi reviewer xem.
06
Reviewer xem xét, request changes
👤 @techLead · Code Review
TechLead review logic, naming, performance. Comment inline. DevA sửa theo feedback, push thêm commit. Sau khi approve → Squash & Merge vào develop.
# DevA fix theo review:
git commit -m "refactor(auth): rename handler per review"
git push origin feature/APP-101-user-login
# TechLead approve → Squash & Merge vào develop
# Xoá feature branch sau khi merge
Squash & Merge giữ develop history gọn gàng: 1 feature = 1 commit.
04 · Hotfix Khẩn Cấp
7
Phát hiện bug production nghiêm trọng
👤 @devB + @techLead · Production incident
Bug payment không xử lý được. Tạo hotfix branch từ main (không phải develop) để fix nhanh, không kéo code chưa release.
git checkout main
git checkout -b hotfix/payment-null-pointer
# Fix bug
git commit -m "fix(payment): handle null amount in checkout"
8
Merge hotfix vào main và develop
👤 @techLead · Hotfix deploy
Sau review nhanh, merge hotfix vào main (deploy ngay), tag patch version. Merge vào develop để đảm bảo fix không bị mất ở sprint sau.
# Merge vào main
git checkout main
git merge hotfix/payment-null-pointer
# Sync develop
git checkout develop
git merge hotfix/payment-null-pointer
git branch -d hotfix/payment-null-pointer
Nếu đang có release branch, cần merge hotfix vào release branch đó nữa.