Git code - Win - Vps Ubuntu

🧠 Sơ đồ chuẩn hệ thống

homielab (repo gốc)
        ↑
    upstream
        ↑
buildertv (repo anh push code)
        ↑
    origin
        ↑
Máy Win (dev)
        ↓
    git push
GitHubVPS Ubuntu (production)

=========================

PHẦN 1 – CẤU HÌNH CHUẨN TRÊN MÁY WIN

=========================

1️⃣ Kiểm tra remote

git remote -v

Phải là:

origin   https://github.com/buildertv/giapha-os.git
upstream https://github.com/homielab/giapha-os.git

Nếu đúng → không cần sửa gì.


2️⃣ Luôn làm việc trên branch custom

git checkout custom

=========================

PHẦN 2 – QUY TRÌNH DEV HÀNG NGÀY (WIN)

=========================

🔹 Khi sửa code

git checkout custom
git add .
git commit -m "Mô tả thay đổi"
git push origin custom

Xong.


=========================

PHẦN 3 – KHI TÁC GIẢ UPDATE REPO GỐC

=========================

Bước 1 – Update main từ upstream

git checkout main
git fetch upstream
git merge upstream/main

Bước 2 – Merge main vào custom

git checkout custom
git merge main

Nếu có conflict:

  • main là code gốc
  • custom là code anh sửa

Chọn tuỳ tình huống.


Bước 3 – Push lại custom

git push origin custom

=========================

PHẦN 4 – DEPLOY TRÊN VPS UBUNTU

=========================

🎯 Nguyên tắc:

  • VPS KHÔNG sửa code
  • VPS KHÔNG push
  • VPS chỉ pull/reset theo GitHub

1️⃣ Lần đầu clone

git clone -b custom https://github.com/buildertv/giapha-os.git
cd giapha-os
bun install
bun run build
pm2 start ecosystem.config.js

2️⃣ Mỗi lần anh update từ Win

SSH vào VPS:

cd /home/giapha-os
git fetch origin
git reset --hard origin/custom
bun install
bun run build
pm2 restart giapha

👉 reset --hard để đảm bảo production giống GitHub 100%


=========================

PHẦN 5 – QUY TRÌNH CHUẨN NHẤT (TÓM TẮT)

=========================

🖥 Trên Windows

git checkout custom
git add .
git commit -m "update"
git push origin custom

🖥 Trên VPS

git fetch origin
git reset --hard origin/custom
bun install
bun run build
pm2 restart giapha

=========================

PHẦN 6 – CẤU TRÚC NHÁNH ĐÚNG

=========================

  • main = mirror repo gốc
  • custom = toàn bộ code anh sửa
  • VPS chạy custom

🚀 Mô hình của anh bây giờ đã chuẩn DevOps nhỏ gọn

✔ Tách dev / production ✔ Không sửa trực tiếp trên VPS ✔ Không làm bẩn main ✔ Có thể update repo gốc bất kỳ lúc nào


Đăng nhận xét

Mới hơn Cũ hơn