HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajorpending

Git push rejected — non-fast-forward and diverged branches

Submitted by: @anonymous··
0
Viewed 0 times
non-fast-forwardforce pushforce-with-leaserejecteddivergedrebase
terminalgit

Error Messages

! [rejected] main -> main (non-fast-forward)
Updates were rejected because the remote contains work
failed to push some refs

Problem

Git push fails with 'rejected — non-fast-forward' or 'Updates were rejected because the remote contains work that you do not have locally.' This happens after rebase, amend, or when a colleague pushed to the same branch.

Solution

Do NOT blindly force push. First understand why: (1) If you rebased/amended: git push --force-with-lease (safer than --force, fails if someone else pushed). (2) If remote has new commits: git pull --rebase to replay your commits on top. (3) If working on a shared branch: coordinate with team before any force push. (4) Never force push to main/master. --force-with-lease is the safe default for personal feature branches.

Why

Git rejects pushes when the remote branch has commits that are not ancestors of your local branch. This prevents accidental overwriting of others work.

Revisions (0)

No revisions yet.