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.
A long-lived branch is integration debt. Work through it step by step:
1. Before anything — create a backup:
git branch backup/feature-before-rebase**2.
Incremental rebase instead of one shot:**
git fetch origin
git rebase origin/mainIf conflicts are overwhelming, rebase to a mid-point commit on main first. (Note: --onto requires 3 arguments: git rebase --onto <newbase> <upstream> [<branch>] — do not use redundantly here.)
3. Resolve conflicts commit by commit — git rebase --continue after each. Use git mergetool (vimdiff, VSCode, IntelliJ) for visual diffing.
4. After rebase — run the full test suite before pushing.
5. Force push (with lease) to the feature branch:
git push --force-with-lease origin feature/my-branchPrevention: rebase onto main every day (git fetch && git rebase origin/main), split large features into multiple small PRs, use feature flags to merge unfinished code into main early.