Pull Request
Pull Request là gì?
Pull Request (PR) là yêu cầu merge code từ một branch vào branch khác. Đây là cách phổ biến để:
- Đề xuất thay đổi vào dự án
- Review code trước khi merge
- Thảo luận về implementation
💡 GitLab gọi là “Merge Request” (MR), nhưng ý nghĩa giống nhau.
Khi nào tạo Pull Request?
- Hoàn thành một tính năng
- Sửa xong một bug
- Muốn đóng góp vào dự án open source
- Muốn code được review trước khi merge
Bước 1: Chuẩn bị code
# Tạo branch mới
git checkout -b feature/my-feature
# Code và commit
git add .
git commit -m "feat: add new feature"
# Push lên GitHub
git push -u origin feature/my-featureBước 2: Tạo Pull Request
- Vào repository trên GitHub
- Nhấn Pull requests tab
- Nhấn New pull request
- Chọn:
- base: branch đích (thường là
main) - compare: branch của bạn (
feature/my-feature)
- base: branch đích (thường là
- Nhấn Create pull request
Bước 3: Điền thông tin
Title
Mô tả ngắn gọn thay đổi:
feat: Add user authentication
fix: Resolve payment calculation bug
docs: Update API documentationDescription
Template phổ biến:
## Mô tả
Giải thích thay đổi đã làm.
## Loại thay đổi
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update
## Checklist
- [ ] Đã test locally
- [ ] Đã cập nhật documentation
- [ ] Đã thêm unit tests
## Screenshots (nếu có UI)Bước 4: Code Review
Reviewer sẽ:
- Xem code changes
- Comment góp ý
- Approve hoặc Request changes
Bạn cần:
- Trả lời comments
- Sửa code theo góp ý
- Push thêm commits
# Sửa theo review
git add .
git commit -m "fix: address review comments"
git pushBước 5: Merge
Sau khi PR được approve:
- Merge commit: Giữ tất cả commits + merge commit
- Squash and merge: Gộp tất cả thành 1 commit
- Rebase and merge: Rebase rồi merge (không merge commit)
💡 Nhiều team chọn “Squash and merge” để lịch sử sạch hơn.
Draft Pull Request
Tạo PR chưa hoàn thành để:
- Lấy feedback sớm
- Thảo luận approach
- CI chạy thử
Nhấn Convert to draft hoặc tạo với dropdown “Create draft pull request”.
Tiếp theo
Học cách Fork Repository để đóng góp vào dự án open source!
Last updated on