main(production): Nhánh chính chứa code productionstaging: Nhánh staging để kiểm thử trước khi deploy lên productiondevelop: Nhánh phát triển chính, nơi tích hợp code từ các feature branches
feature/*: Các nhánh feature để phát triển tính năng mớihotfix/*: Các nhánh để sửa lỗi khẩn cấp trên production/staging
- 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- 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-nangkhi 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
- Tạo Pull Request từ
feature/ten-tinh-nangvàostaging
- Review code
- Sửa code theo comment nếu cần
- merge vào
stagingkhi được approve
- 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
- 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
- Tạo Pull Request từ
release/v1.x.xvàomain - Sau khi merge vào main, merge ngược lại vào
stagingvàdevelop
- Khi cần sửa lỗi khẩn cấp trên production:
git checkout main
git checkout -b hotfix/ten-loi- Sửa lỗi và tạo Pull Request vào
main - Sau khi merge, merge ngược lại vào
stagingvàdevelop
- Không commit trực tiếp vào các nhánh chính (
main,staging,develop) - Bắt buộc review code trước khi merge vào
stagingvàmain - Tag version phải tuân theo semantic versioning (MAJOR.MINOR.PATCH)
- 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"