Force push ACCEPTABLE:
1. Feature branch của riêng bạn, chưa ai review/pull: sau git rebase -i để clean up commits trước PR
2. Personal fork: không ảnh hưởng ai
3. Sau git commit --amend trên branch riêng: cần update remote
4. Reset --hard và force push trên branch riêng nếu bạn vô tình push nhầm (credentials, large file)
Force push KHÔNG BAO GIỜ:
1. main / master / develop — bất kỳ shared long-lived branch
2. Branch đang có open PR mà người khác đang review
3. Branch mà CI/CD đang build/deploy từ đó
4. Tag đã được release — git tags không nên bị move
Kiểm tra trước khi force push:
# Ai đã pull branch này?
git log origin/feature/my-branch..feature/my-branch # commits chỉ có local
git log feature/my-branch..origin/feature/my-branch # commits chỉ có remote
# Nếu remote có commits bạn không có → người khác đã push → KHÔNG force pushRule đơn giản: nếu phải hỏi "force push được không?" → không.
Chỉ force push khi chắc 100% bạn là người duy nhất dùng branch đó.
Force push ACCEPTABLE:
1. Your own feature branch, nobody has reviewed/pulled it: after git rebase -i to clean up commits before a PR
2. Personal fork: does not affect anyone
3. After git commit --amend on your own branch: need to update remote
4. Hard reset + force push on your own branch if you accidentally pushed credentials or a large file
Force push NEVER:
1. main / master / develop — any shared long-lived branch
2. A branch that has an open PR others are actively reviewing
3. A branch that CI/CD is building/deploying from
4. A released tag — git tags should never be moved
Check before force pushing:
# What is local-only vs remote-only?
git log origin/feature/my-branch..feature/my-branch # local-only commits
git log feature/my-branch..origin/feature/my-branch # remote-only commits
# If remote has commits you do not have → someone else pushed → DO NOT force pushSimple rule: if you have to ask "can I force push?" — you cannot.
Only force push when you are 100% certain you are the only one using that branch.