Skip to Content

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?

  1. Hoàn thành một tính năng
  2. Sửa xong một bug
  3. Muốn đóng góp vào dự án open source
  4. 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-feature

Bước 2: Tạo Pull Request

  1. Vào repository trên GitHub
  2. Nhấn Pull requests tab
  3. Nhấn New pull request
  4. Chọn:
    • base: branch đích (thường là main)
    • compare: branch của bạn (feature/my-feature)
  5. 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 documentation

Description

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 push

Bước 5: Merge

Sau khi PR được approve:

  1. Merge commit: Giữ tất cả commits + merge commit
  2. Squash and merge: Gộp tất cả thành 1 commit
  3. 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