CS FundamentalsHardProduct-company placement · Git interview

After rebasing your branch you must update the remote branch. A colleague may have pushed to the same branch meanwhile. Why prefer git push --force-with-lease over git push --force?

  1. A. --force-with-lease squashes your commits before pushing
  2. B. --force-with-lease pushes tags as well
  3. C. --force-with-lease refuses to overwrite if the remote branch has moved from what your local remote-tracking ref last saw, so a colleague's new commits are not silently destroyed
  4. D. --force-with-lease creates a backup branch on the remote

Correct answer: C. --force-with-lease refuses to overwrite if the remote branch has moved from what your local remote-tracking ref last saw, so a colleague's new commits are not silently destroyed

--force blindly replaces the remote ref. --force-with-lease only succeeds if the remote still points where you expect, protecting work pushed after your last fetch.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic