git runtime_error ai_generated true

error: failed to push some refs to 'origin' hint: Updates were rejected because the remote contains work that you do not have locally.

ID: git/push-non-fast-forward

Also available as: JSON · Markdown · 中文
88%Fix Rate
87%Confidence
1Evidence
2023-04-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 2.31.0 active
git 2.39.0 active
git 2.44.0 active

Root Cause

Local branch is behind the remote branch; push is rejected to prevent overwriting remote changes.

generic

中文

本地分支落后于远程分支;拒绝推送以防止覆盖远程更改。

Official Documentation

https://git-scm.com/docs/git-push

Workarounds

  1. 90% success Pull the remote changes first: 'git pull origin main --rebase' to rebase local commits on top, then push again.
    Pull the remote changes first: 'git pull origin main --rebase' to rebase local commits on top, then push again.
  2. 85% success If conflicts occur, resolve them manually, then continue the rebase with 'git rebase --continue' and push.
    If conflicts occur, resolve them manually, then continue the rebase with 'git rebase --continue' and push.

中文步骤

  1. Pull the remote changes first: 'git pull origin main --rebase' to rebase local commits on top, then push again.
  2. If conflicts occur, resolve them manually, then continue the rebase with 'git rebase --continue' and push.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Using 'git push --force' may overwrite remote commits and cause data loss for collaborators.

  2. 50% fail

    Running 'git pull' without merging may result in merge conflicts if not handled properly.