Đồng bộ dự án code
Sync code projects ≠ sync như Documents. Có nhiều files không nên sync (node_modules, build artifacts, secrets) vì:
- Dependencies (per-machine binaries) — install lại bằng
npm installnhanh hơn sync - Build outputs — rebuild được, sync waste bandwidth
- Secrets —
.env.localper-machine
Kiến trúc
Phần tiêu đề “Kiến trúc”PC Laptop┌──────────────────────────┐ ┌──────────────────────────┐│ ~/projects/ │ ←──── sync ──→│ ~/projects/ ││ ├─ project-a/ │ (source) │ ├─ project-a/ ││ │ ├─ src/ ✅ │ │ │ ├─ src/ ✅ ││ │ ├─ package.json ✅ │ │ │ ├─ package.json ✅ ││ │ ├─ pnpm-lock.yaml ✅ │ │ │ ├─ pnpm-lock.yaml ✅ ││ │ └─ node_modules/ ❌ │ │ │ └─ node_modules/ ❌ ││ │ (installed local) │ │ │ (installed local)││ └─ project-b/ │ │ └─ project-b/ │└──────────────────────────┘ └──────────────────────────┘
After sync: cd project-a && npm install (one-time, both machines)Ignore patterns cho dự án code
Phần tiêu đề “Ignore patterns cho dự án code”# Build artifacts**/node_modules**/dist**/build**/.next**/out**/coverage**/.turbo
# Dependencies caches**/.venv**/venv**/__pycache__**/*.pyc**/.pytest_cache
# Per-machine secrets**/.env.local**/.env.development.local
# Database / data**/data**/postgres-data**/postgres_data**/*.sqlite**/*.db
# Docker volumes (per-machine)**/.docker
# IDE / OS**/.vscode**/.idea**/.DS_Store**/Thumbs.db**/desktop.ini
# Logs + temp**/*.log**/logs**/tmp**/.tmp**/.cacheDependencies — cài lại sau khi đồng bộ
Phần tiêu đề “Dependencies — cài lại sau khi đồng bộ”cd ~/projectsfor proj in project-a project-b; do echo "=== Installing $proj ===" cd ~/projects/$proj && npm install && cd ~/projectsdone# Enable pnpm via corepack (Node 22+)corepack enable
cd ~/projectsfor proj in project-a project-b; do cd ~/projects/$proj && pnpm install && cd ~/projectsdonecd ~/projects/project-pypython3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txt⚠ .venv/ đã trong ignore patterns → mỗi máy có venv riêng.
Workflow Git + sync — KHÔNG conflict
Phần tiêu đề “Workflow Git + sync — KHÔNG conflict”Câu hỏi phổ biến: “Sync .git/ folder thì git có break không?”
Trả lời: KHÔNG, sync .git/ thường safe. .git/ chứa:
objects/— immutable content-addressed (hash = unique)refs/— pointer files, append-only natureHEAD,index— current state
Edge case có thể conflict:
- 2 máy commit cùng branch lúc 1 máy offline → 2 different
refs/heads/<branch>content - Mitigation: pull/push qua git remote là source of truth, không rely 100% Syncthing
Best practice:
- Commit + push lên remote (GitHub/GitLab) trước khi switch máy
- Switch máy → mở project → check
git statusclean - Pull mới từ remote:
git pull— pickup changes - Tiếp tục work
→ Syncthing sync working dir + uncommitted changes. Git remote = canonical history.
Sync .git/ hay bỏ qua?
Phần tiêu đề “Sync .git/ hay bỏ qua?”Pros:
- Preserve uncommitted commits
- Working dir + git state in-sync
- Branch state consistent
Cons:
- Tốn space (vd opencode
.git/có thể >1GB) - Per-machine
objects/packrebuild khigit gc
**/.gitPros:
- Smaller sync footprint
- No conflict on
refs/
Cons:
- Mỗi máy
git clonelại từ remote - Mất uncommitted local commits/branches
→ Em recommend sync .git/ trừ khi space rất tight.
Quy trình hàng ngày
Phần tiêu đề “Quy trình hàng ngày”-
Trước khi switch máy: commit work-in-progress (vd
git commit -am "WIP") — không bắt buộc nhưng best practice -
Đóng IDE — release file locks
-
Đợi 30s — Syncthing flush
-
Mở máy kia → IDE → continue work
-
Pull remote nếu có changes từ teammates:
git pull
Bonus: đồng bộ dự án local (không có git remote)
Phần tiêu đề “Bonus: đồng bộ dự án local (không có git remote)”Cho projects không có GitHub/GitLab remote (vd ~/projects/n8n/ — local Docker stack):
- Sync via Syncthing là backup duy nhất
- ⚠ Nếu cả 2 máy fail → mất source. Fix: weekly tar archive vào shared folder hoặc cloud
- Hoặc tạo private GitHub repo:
cd ~/projects/n8ngh repo create AI-Workforce-Solutions/n8n-private --private --source=. --pushBước tiếp theo
Phần tiêu đề “Bước tiếp theo”- AI agent prompts — autonomous setup
- Common issues — fix sync conflicts