git push --force origin

Forcefully updates the `origin` remote with your local commits, overwriting any conflicting history.

This command forces a push of your local branch to rewrite the origin remote history, ensuring your local changes replace what’s on the remote even if they diverge.

The --force flag tells Git to update the remote ref even if it results in a non-fast-forward update, effectively overwriting remote commits; origin specifies the target remote repository name; you can optionally specify a branch name after origin to push only that branch.

You can use the shorthand -f instead of --force, or choose --force-with-lease for a safer push that checks the remote hasn’t changed since your last fetch; to target a specific branch, append its name like git push -f origin feature-branch; related commands include git push --dry-run to preview the push and a plain git push for a standard fast-forward update.

Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...