Home / Localhost / Git push rejected

Git push rejected: fetch first and non-fast-forward errors

Fix "! [rejected] main -> main (fetch first)" and "failed to push some refs": pull the remote changes, handle protected branches and big files.

A rejected push means the remote branch has commits that your copy does not have, or the server refuses the push for another reason. The message after "rejected" tells you which. Do not reach for --force before you know why.

What to do, step by step

  1. Read the line in brackets: fetch first or non-fast-forward means the remote has new commits.
  2. Get them: git pull --rebase puts your commits on top of the remote ones. git pull makes a merge commit instead.
  3. If Git reports conflicts, fix the marked files, then git add them and git rebase --continue (or finish the merge).
  4. Push again: git push.
  5. Only if you rewrote history on purpose, such as after a rebase of your own branch, push with git push --force-with-lease. It refuses to overwrite work you have not seen.

Commands you can copy

Get the remote changes and replay your commits on top
git pull --rebase
Safer force push after rewriting your own branch
git push --force-with-lease
Push the current branch to a new branch name
git push origin HEAD:my-branch
See where your remote points
git remote -v

Other causes to check

remote rejected: protected branch hook declined
The branch needs a pull request or checks before changes. Push to a new branch with git push origin HEAD:my-branch and open a pull request.
GH001: Large files detected
GitHub blocks files over 100 MB. Remove the file from the commit, and use Git LFS for big files. Deleting it in a later commit is not enough, since it is still in history.
Permission denied or 403
Your account has no write access, or the saved login is for another account. Check with git remote -v and sign in with the right account or key.
refusing to update checked out branch
You pushed to a non-bare repository. Push to a bare repository, or use a different branch.
Updates were rejected because the tag already exists
A tag with that name is already on the remote. Use a new tag name, or delete the old one on purpose.

Questions about Git push rejected

What does non-fast-forward mean?
Your push would not simply add commits on top of the remote branch, because the remote has commits you lack. Git refuses so that nobody loses work.
Is git push --force safe?
It overwrites the remote branch with yours and can delete other people's commits. Use --force-with-lease, and only on a branch where you are sure.
Should I pull with rebase or merge?
Rebase keeps a straight history. Merge keeps the exact order things happened. Pick what your team uses.

Updated 2026-10-11

Config generators for this

Related pages