← Quay lại blog
·1 min read

Git Workflow Cho Dự Án Cá Nhân

Dù làm một mình, một git workflow tốt giúp bạn quản lý code hiệu quả hơn.

Branch Strategy

main          ← production-ready code
├── feature/* ← tính năng mới
├── fix/*     ← sửa lỗi
└── chore/*   ← refactor, docs, config

Conventional Commits

Dùng prefix cho commit messages:

feat: add dark mode toggle
fix: resolve hydration mismatch
docs: update README
chore: upgrade dependencies
refactor: extract PostCard component

Useful Git Commands

Xem thay đổi trước khi commit

git diff --staged  # Xem những gì sẽ được commit
git log --oneline --graph  # Xem lịch sử đẹp

Stash khi cần chuyển branch

git stash push -m "WIP: feature X"
git stash list
git stash pop

Interactive rebase (cẩn thận!)

git rebase -i HEAD~3  # Gộp/sửa 3 commits gần nhất

.gitignore Essentials

node_modules/
.next/
.env.local
.env*.local
*.log
.DS_Store

Git Hooks Với Husky

npm install -D husky lint-staged
npx husky init
{
  "lint-staged": {
    "*.{ts,tsx}": ["eslint --fix", "prettier --write"]
  }
}

Một workflow đơn giản nhưng nhất quán sẽ giúp bạn rất nhiều về lâu dài.

Nhận bài viết mới

Bài viết mới gửi thẳng vào inbox. Không spam, unsubscribe bất cứ lúc nào.