Interview Q&A / Git & GitHub

IntermediateQuick answer1 min readUpdated 3 Oct 2026

What is the difference between git push --force and --force-with-lease?

SHORT ANSWER

--force overwrites the remote branch no matter what. --force-with-lease overwrites only if the remote is still where you last saw it, so you do not wipe out commits a teammate pushed meanwhile.

Explain it simply

Imagine replacing a shared notice with a new one. --force tears down whatever is hanging there. --force-with-lease first checks the notice is the same one you saw when you last looked; if someone changed it, you stop.

Git compares the remote branch with your remote-tracking ref (origin/feature). If they match, the push goes through. If a teammate pushed after your last fetch, it fails and you can fetch and review. It is the sensible default after an amend or rebase on your own pushed branch. It is not perfect, because an automatic background fetch can update your reference and fool the check.

Example

bash
git rebase main
git push --force-with-lease origin feature/search
# ! [rejected] (stale info)  -> someone pushed; fetch and review

What to say in the interview

"--force overwrites the remote unconditionally, while --force-with-lease fails if the remote has commits I have not seen. After rebasing my own branch I use --force-with-lease so I never silently delete a teammate's work."

#git#push#force

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.