Interview Prep/Git & GitHub/Remotes, Collaboration and Pull Requests

Why do you use `--force-with-lease`, and when does it still hurt?

IntermediateScenarioRemotes, Collaboration and Pull Requests
Answer

Situation read → After rebasing, you must overwrite the remote branch, but you want protection against deleting a teammate's new commits.

What I'd do →

  1. git push --force-with-lease origin feature.
  2. Pin the expected tip for more safety: --force-with-lease=feature:<sha>; add --force-if-includes (Git 2.30+).
  3. Avoid running git fetch in the background (IDE auto-fetch) before pushing, because that updates the remote-tracking ref and defeats the lease check.

Why → The push only succeeds if the remote ref still equals what you last saw.

Interview tip → Plain --force never checks anything, so ban it on shared branches.

All Git & GitHub questions Roadmap: Git & GitHub

More on Remotes, Collaboration and Pull Requests