Error fixDevOps · 3 min read · Updated 5 Dec 2026

Git "failed to push some refs" (rejected, non-fast-forward): Fix

Fix "! [rejected] main -> main (fetch first)" and "failed to push some refs": pull or rebase first, handle protected branches and avoid unsafe force pushes.

QUICK ANSWER"failed to push some refs" with "rejected (fetch first)" or "non-fast-forward" means the remote branch has commits you do not have, so Git refuses to overwrite them. Run git pull --rebase (or git pull), resolve any conflicts, then push again. If the branch is protected, push to a new branch and open a pull request. Use git push --force-with-lease only for your own branch after a rebase.
Git push rejected: causes and fixes
Git push rejected: causes and fixes

The messages and what they mean

MessageMeaningFix
rejected (fetch first) / non-fast-forwardRemote has new commitsgit pull --rebase, then push
protected branch hook declinedDirect pushes to main are blockedPush a branch, open a PR
src refspec main does not match anyNo local commit or branch named mainCommit first; check git branch (maybe it is master)
Permission denied (publickey) / 403Authentication problemFix SSH key or use a token; check repo access
remote: error: File is 120 MB; exceeds 100 MBFile too large for GitHubRemove it from history; use Git LFS

Fix the usual case

  1. Fetch and replay your commits on top of the remote: git pull --rebase origin main.
  2. If there are conflicts, fix them, git add the files and run git rebase --continue.
  3. Run the tests.
  4. Push: git push origin main (or your branch).
git pull --rebase origin main
# fix conflicts if any, then
git push origin main

When force push is OK, and when it is not

After rebasing your own feature branch, the remote history differs from yours, so a normal push is rejected. Use git push --force-with-lease: it overwrites only if nobody else pushed since you last fetched.

Never force push to main or a shared branch. It can delete teammates' commits. Most teams block it with branch protection rules.

Prevent it

  • Start each task from an updated main: git switch main && git pull.
  • Work on feature branches and merge through pull requests.
  • Set git config --global pull.rebase true if your team prefers a linear history.

Questions

Will git pull delete my work?

No. It merges or rebases the remote commits with yours. If something goes wrong, git reflog shows every previous state so you can go back.

What is the difference between --force and --force-with-lease?

--force overwrites the remote no matter what. --force-with-lease refuses if the remote has commits you have not seen, which protects teammates' work.