Branch sống lâu là nợ kỹ thuật về integration. Xử lý từng bước:
1. Trước khi làm bất cứ điều gì — tạo backup:
git branch backup/feature-before-rebase**2.
Rebase từng phần (incremental rebase) thay vì một lần:**
git fetch origin
git rebase origin/mainNếu conflict quá nhiều, rebase tới mid-point commit của main trước. (Lưu ý: --onto yêu cầu 3 tham số: git rebase --onto <newbase> <upstream> [<branch>] — không dùng redundant ở đây.)
3. Resolve conflicts theo từng commit — git rebase --continue sau mỗi conflict. Dùng git mergetool (vimdiff, VSCode, IntelliJ) để visual diff.
4. Sau rebase — chạy full test suite trước khi push.
5. Force push (với lease) lên feature branch:
git push --force-with-lease origin feature/my-branchPhòng tránh lần sau: rebase lên main mỗi ngày (hoặc dùng git fetch && git rebase origin/main), chia feature lớn thành nhiều PR nhỏ, dùng feature flags để merge code chưa hoàn thiện vào main sớm.