Git
gitgitTroubleshootingBeginner
Updates were rejected: non-fast-forward push
Safely resolve Git rejected push errors by rebasing and reconciling divergent remote history without data loss.
Verified: 2026-09-30
Tested on:git 2.44+
Platforms:
all
#git#push#rebase#non-fast-forward
Error Message
To https://github.com/iamtashanto/OpenDevDocs.git
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/iamtashanto/OpenDevDocs.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.Symptoms
git push origin <branch>fails with[rejected] (non-fast-forward).- Git warns that the tip of your local branch is behind the remote counterpart.
Why It Happens
Git prevents you from overwriting commits on the remote branch that you do not have locally in your commit history. This happens when:
- A teammate pushed new commits to the remote branch while you were working.
- A PR was merged on GitHub directly into the branch.
- You previously amended or rebased local commits that were already pushed.
Quick Fix (Recommended)
Fetch the remote commits and replay your local commits on top using Rebase:
# 1. Fetch remote changes and rebase your commits on top
git pull --rebase origin main
# 2. Push your rebased branch cleanly
git push origin mainStep-by-Step Resolution
What NOT to Do: Dangerous Force Pushing
Blocked by CORS Policy: No 'Access-Control-Allow-Origin'
Resolve browser CORS errors in React, Next.js, Express, and Nginx reverse proxies with correct response headers.
Docker: Bind for 0.0.0.0:PORT failed: port is already allocated
Fix port conflict errors in Docker and Docker Compose when another container or host service is already listening on the requested port.