Coding⏱️ 2 min read📅 2026-05-31

How to Fix: Git push failed, "Non-fast forward updates were rejected"

Git push failed due to non-fast forward updates. Resolve by using git push -f or git merge --allow-unrelated-histories.

Quick Answer: Use git push -f to force the update or git merge --allow-unrelated-histories to allow unrelated histories.

When you try to push local code changes to a remote Git repository, and you encounter the error 'Git push failed, To prevent from losing history, non-fast forwardupdates were rejected', it's because the pushed commits are not compatible with the existing commit history on the remote branch. This is often due to editing your repository via Git Online.

🔍 Why This Happens

  • [Cause]

🚀 How to Resolve This Issue

Method 1: Force Push

  1. Step 1: Use the command `git push --force-with-lease origin ` to force-push your changes. This will update the remote branch, but be cautious as it may overwrite other people's changes.

Method 2: Rebase

  1. Step 1: Use the command `git push origin --rebase` to rebase your changes onto the latest commit on the remote branch. This will preserve the commit history, but may require additional steps if you have uncommitted changes.

✨ Wrapping Up

Before proceeding, make sure to check the remote branch's last commit using `git log origin/`. If you're unsure about which method to use or how to apply it, consider seeking help from a colleague or a Git expert.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions