git push rejected: failed to push some refs
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/you/app.git'
hint: Updates were rejected because the remote contains work that you do not have locally.In one sentence: GitHub has commits your computer doesn't, so Git refuses to overwrite them. Pull those commits in first, then push.
What it means
Git only lets you push if your branch already includes everything on the remote. If someone (or something) added commits on GitHub since you last pulled, your push would erase them, so Git rejects it. The `non-fast-forward` wording means the same thing.
This is very common when you mix tools: Lovable, Bolt, v0 or the GitHub website commit to the repo while you also edit locally in Cursor.
Common causes
- An AI builder synced changes to GitHub after your last pull.
- You created the repo on GitHub with a README or license, then tried to push a separate local project into it.
- You edited a file on the GitHub website, or pushed from another computer.
- You amended or rebased commits that were already pushed.
How to fix it
- Commit or stash your local changes so your working tree is clean.
- Pull the remote work and replay yours on top: `git pull --rebase origin main`.
- If Git reports conflicts, open the listed files, keep the right lines, then `git add` them and run `git rebase --continue`.
- Push again with `git push origin main`.
- Don't use `git push --force` to make the error go away. It deletes the remote commits. Only force-push if you're certain those commits should be thrown out, and prefer `--force-with-lease`.
Example
git status # make sure everything is committed
git pull --rebase origin main
# fix any conflicts, then: git add <file> && git rebase --continue
git push origin mainTried this and it's still broken? Paste your exact error for a free explanation of your specific case.
Prompt to paste into your AI tool
git push was rejected with 'failed to push some refs' / 'Updates were rejected because the remote contains work that you do not have locally'. Walk me through safely pulling the remote commits with git pull --rebase, resolving any conflicts without losing work on either side, and pushing again. Do not force-push.Still stuck?
Paste your exact error and code. Get a plain-English explanation free, or the full fix for $5.
Hitting errors every day? Builder is $15/mo for 100 fixes per month. Compare plans
Related errors
- TypeError: Cannot read properties of undefined
- CORS error: blocked by CORS policy
- Hydration failed: server HTML didn't match the client (Next.js)
- Module not found: Can't resolve '...'
Weekly: the errors breaking vibe-coded apps and how to fix them. Free.
No spam. Unsubscribe anytime.