Bỏ qua

Branching Strategy — Git Flow

Mô hình Branching

Project sử dụng Git Flow với 3 môi trường (Local → Test → Production), đảm bảo code được verify trước khi lên production.

graph LR
    F["🔧 feature/*"] -->|PR & merge| D["🔀 develop"]
    D -->|merge| S["🧪 staging"]
    S -->|verify OK, merge| M["🚀 main"]
    H["🚑 hotfix/*"] -->|emergency| M
    H -->|cherry-pick| D

Các nhánh chính

Branch Môi trường Mục đích Protected
main Production Code đang chạy trên prod
staging Test/Staging Code đang test, chờ verify
develop Development Integration branch
feature/* Local Feature đang phát triển
hotfix/* Local → Prod Fix khẩn cấp

Quy trình làm việc

Feature Development

graph LR
    A["1. Tạo branch<br/>feature/tên-feature"] --> B["2. Code & Commit<br/>trên local"]
    B --> C["3. Push & tạo PR<br/>vào develop"]
    C --> D["4. Code Review<br/>& Approve"]
    D --> E["5. Merge vào<br/>develop"]
# 1. Tạo branch từ develop
git checkout develop
git pull origin develop
git checkout -b feature/add-user-profile

# 2. Code, commit
git add .
git commit -m "feat: add user profile page"

# 3. Push & tạo Pull Request vào develop
git push origin feature/add-user-profile
# → Tạo PR trên GitHub: feature/add-user-profile → develop

Release to Staging (Test)

# Merge develop vào staging để test
git checkout staging
git pull origin staging
git merge develop
git push origin staging
# → Auto-deploy lên test.chienle.dev

Luôn test trên staging trước

Không bao giờ merge trực tiếp developmain. Code phải qua staging để QA/tester verify.

Deploy to Production

# Sau khi staging đã verify OK
git checkout main
git pull origin main
git merge staging
git push origin main
# → Auto-deploy lên chienle.dev

Hotfix (Fix khẩn cấp)

graph LR
    A["1. Branch từ main<br/>hotfix/fix-bug"] --> B["2. Fix & Test<br/>local"]
    B --> C["3. Merge vào main<br/>(deploy prod)"]
    C --> D["4. Cherry-pick<br/>vào develop"]
# 1. Tạo hotfix từ main
git checkout main
git checkout -b hotfix/fix-crash-on-upload

# 2. Fix, commit, push
git commit -m "fix: handle null file_key in upload"
git push origin hotfix/fix-crash-on-upload

# 3. Tạo PR vào main (review nhanh)
# → Merge & deploy prod

# 4. Cherry-pick vào develop để sync
git checkout develop
git cherry-pick <commit-hash>

Commit Convention

Sử dụng Conventional Commits:

Prefix Mô tả Ví dụ
feat: Tính năng mới feat: add course search
fix: Sửa bug fix: handle null thumbnail
docs: Chỉ thay đổi docs docs: update API endpoints
refactor: Refactor code refactor: extract upload service
chore: Maintenance chore: update dependencies
style: CSS/formatting style: fix card alignment
test: Thêm/sửa tests test: add course CRUD tests

Pull Request Rules

  • PR phải có ít nhất 1 reviewer approve trước khi merge
  • PR title theo commit convention
  • Không merge nếu CI/CD fail
  • Squash merge vào develop, merge commit vào staging/main