Skip to content

Instantly share code, notes, and snippets.

@Phathdt
Last active March 13, 2025 09:31
Show Gist options
  • Select an option

  • Save Phathdt/8df69d1988eb24f3069d8ca348a5c8a2 to your computer and use it in GitHub Desktop.

Select an option

Save Phathdt/8df69d1988eb24f3069d8ca348a5c8a2 to your computer and use it in GitHub Desktop.

Quy trình GitFlow

1. Cấu trúc nhánh

Các nhánh chính (Long-running branches)

  • main (production): Nhánh chính chứa code production
  • staging: Nhánh staging để kiểm thử trước khi deploy lên production
  • develop: Nhánh phát triển chính, nơi tích hợp code từ các feature branches

Các nhánh phụ (Short-lived branches)

  • feature/*: Các nhánh feature để phát triển tính năng mới
  • hotfix/*: Các nhánh để sửa lỗi khẩn cấp trên production/staging

2. Quy trình làm việc

2.1. Phát triển tính năng mới

  1. Checkout từ nhánh main để tạo nhánh feature mới (đảm bảo code base ổn định):
git checkout main
git pull origin main
git checkout -b feature/ten-tinh-nang
  1. Phát triển tính năng trên nhánh feature
git add .
git commit -m "feat: mô tả tính năng"
git push origin feature/ten-tinh-nang

khi cần check ở dev thì cứ tạo pr và merge vào develop, auto deploy dev để check

nhánh dev thỉnh thoảng sẽ được reset lại bằng nhánh staging

  1. Tạo Pull Request từ feature/ten-tinh-nang vào staging
  • Review code
  • Sửa code theo comment nếu cần
  • merge vào staging khi được approve

2.2. Fix trên staging

  • Tạo nhánh hotfix từ staging
  • Fix lỗi và tạo PR vào staging
  • Review code
  • Merge khi được approve

Sau khi verify lỗi đã được sửa:

  • Nếu chưa release: tiếp tục quy trình release bình thường
  • Nếu đã release: merge hotfix vào main qua quy trình release tiêu chuẩn

2.3. Quy trình Release

  1. Khi code trên staging đã sẵn sàng để release:
  • Chaỵ CICD để tạo tag release/v1.x.x
  • Update argocd để deploy code lên production
  1. Tạo Pull Request từ release/v1.x.x vào main
  2. Sau khi merge vào main, merge ngược lại vào stagingdevelop

2.4. Hotfix

  1. Khi cần sửa lỗi khẩn cấp trên production:
git checkout main
git checkout -b hotfix/ten-loi
  1. Sửa lỗi và tạo Pull Request vào main
  2. Sau khi merge, merge ngược lại vào stagingdevelop

3. Quy tắc quan trọng

  1. Không commit trực tiếp vào các nhánh chính (main, staging, develop)
  2. Bắt buộc review code trước khi merge vào stagingmain
  3. Tag version phải tuân theo semantic versioning (MAJOR.MINOR.PATCH)
  4. Commit message phải rõ ràng và tuân theo format:
    • feat: tính năng mới
    • fix: sửa lỗi
    • docs: thêm/sửa tài liệu
    • style: format code
    • refactor: tái cấu trúc code
    • test: thêm/sửa test
    • chore: công việc linh tinh khác
gitGraph
    commit id: "Initial commit"
    branch develop
    checkout develop
    commit id: "Setup develop branch"
    
    branch feature/feature1
    checkout feature/feature1
    commit id: "Start feature 1"
    commit id: "Work on feature 1"
    commit id: "Complete feature 1"
    checkout develop
    merge feature/feature1 id: "Merge feature 1 to develop"

    branch staging
    checkout staging
    commit id: "Setup staging branch"
    merge develop id: "Merge develop to staging"
    
    branch feature/feature2
    checkout feature/feature2
    commit id: "Start feature 2"
    commit id: "Complete feature 2"
    checkout staging
    merge feature/feature2 id: "Feature 2 to staging"
    
    branch hotfix/staging-fix
    checkout hotfix/staging-fix
    commit id: "Fix issue in staging"
    checkout staging
    merge hotfix/staging-fix id: "Apply fix to staging"
    
    checkout main
    commit id: "Production setup"
    
    branch release/v1.0.0
    checkout release/v1.0.0
    commit id: "Prepare v1.0.0"
    checkout main
    merge release/v1.0.0 id: "Release v1.0.0"
    
    branch hotfix/prod-issue
    checkout hotfix/prod-issue
    commit id: "Fix production issue"
    checkout main
    merge hotfix/prod-issue id: "Hotfix to production"
    checkout staging
    merge hotfix/prod-issue id: "Backport hotfix to staging"
    checkout develop
    merge hotfix/prod-issue id: "Backport hotfix to develop"
    
    checkout staging
    merge develop id: "Sync develop to staging"
    
    branch feature/feature3
    checkout feature/feature3
    commit id: "New feature 3"
    checkout staging
    merge feature/feature3 id: "Feature 3 to staging"
    
    branch release/v1.1.0
    checkout release/v1.1.0
    commit id: "Prepare v1.1.0"
    checkout main
    merge release/v1.1.0 id: "Release v1.1.0"
    checkout staging
    merge main id: "Sync main to staging"
    checkout develop
    merge staging id: "Reset develop from staging"
Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment