Nội dung bài họcLesson content
Git là gì? Tại sao cần?What is Git? Why do you need it?
Git là hệ thống quản lý phiên bản (version control). Nó lưu lịch sử mọi thay đổi của code, giúp bạn quay lại phiên bản cũ nếu sai. Git cũng giúp nhiều người làm việc cùng nhau trên 1 dự án. GitHub là dịch vụ lưu Git repo online.Git is a version control system. It saves the history of every code change, letting you go back to an old version if you make a mistake. Git also helps multiple people work together on 1 project. GitHub is a service that stores Git repos online.
Khởi tạo repo và commit đầu tiênInitialize a repo and first commit
git init tạo repo mới trong thư mục hiện tại. git add . đưa tất cả file vào "staging area" (chờ commit). git commit -m "mô tả" lưu snapshot. Mỗi commit cần thông điệp rõ ràng: "feat: thêm trang chủ" hoặc "fix: sửa lỗi đăng nhập".git init creates a new repo in the current directory. git add . puts all files into the "staging area" (waiting to commit). git commit -m "description" saves a snapshot. Each commit needs a clear message: "feat: add homepage" or "fix: fix login bug".
# Tạo repo mới
git init
# Tạo file và stage
echo "print('Hello')" > hello.py
git add .
# Commit đầu tiên
git commit -m "feat: thêm file hello.py"
# Xem lịch sử
git log --oneline
# Output: a1b2c3d feat: thêm file hello.py
git status và git loggit status and git log
git status cho biết: file nào đã thay đổi, file nào đã staged, file nào chưa tracked. git log hiển thị lịch sử commit: mã hash, tác giả, ngày, thông điệp. Dùng git log --oneline để xem gọn 1 dòng mỗi commit.git status tells you: which files changed, which are staged, which are untracked. git log shows commit history: hash code, author, date, message. Use git log --oneline for a compact 1-line-per-commit view.
# Kiểm tra trạng thái
git status
# Changes to be committed:
# new file: hello.py
# Xem lịch sử gọn
git log --oneline
# a1b2c3d feat: thêm file hello.py
# e4f5g6h init: khởi tạo repo
# Xem chi tiết 1 commit
git show a1b2c3d
Quy ước commit messageCommit message conventions
Tiền tố phổ biến: feat (tính năng mới), fix (sửa lỗi), docs (tài liệu), style (định dạng), refactor (tái cấu trúc), test (test case), chore (bảo trì). Ví dụ: "feat: thêm trang liên hệ", "fix: sửa lỗi hiển thị giá". Thông điệp ngắn, rõ, mô tả "what" và "why".Common prefixes: feat (new feature), fix (bug fix), docs (documentation), style (formatting), refactor (restructuring), test (test cases), chore (maintenance). Example: "feat: add contact page", "fix: fix price display bug". Messages should be short, clear, describe "what" and "why".