← back to diagnosis

force-pushed over someone

danger

You force-pushed and overwrote a teammate's commits on the remote. The commits may still exist in their local reflog.

On the affected teammate's machine, find the lost commits:

$ git reflog

Find the hash of the commit before the force push, then:

$ git reset --hard <lost-commit-hash>
$ git push --force-with-lease

Use --force-with-lease instead of --force. It will refuse to push if the remote has been updated since your last fetch, preventing you from overwriting yet another person's work.

Set up branch protection rules on your remote (GitHub, GitLab, etc.) to prevent force pushes to shared branches. You can also set a git config alias:

$ git config --global alias.fpush "push --force-with-lease"