Mainframe Path Start learning free
BeginnerError and abend codes! [rejected]

git push rejected (non-fast-forward)

The remote branch has commits you do not have. Integrate them with pull or rebase, then push — do not force over other people's work.

What happened

You ran git push and Git refused to update the remote branch. The output marks the ref with ! and the word rejected.

git push output (illustrative)Illustrative example
$ git push origin main
To github.com:mainframe-learner/mp-batch-jobs.git
 ! [rejected]        main -> main (fetch first)
error: failed to push some refs to 'github.com:mainframe-learner/mp-batch-jobs.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally.

What it means

A push is a fast-forward when your new commit descends from the commit the remote branch points to now. If someone else pushed in the meantime, the remote has commits you lack. Accepting your push would drop them from the branch's history, so Git refuses by default.

In the push output, ! marks a ref that was not updated. rejected means your Git never sent the update, usually because it is not a fast-forward. remote rejected means the server refused it — for example because of a hook, branch protection, or a setting such as receive.denyNonFastForwards.

Typical causes

Symptoms

Where to look

How to diagnose

  1. Run git fetch to update your view of the remote.
  2. Compare local and remote with git log --oneline --graph --all or the two-dot ranges above.
  3. Decide: are the remote commits someone else's real work (integrate them) or your own old version of rewritten history?

How to fix

How to prevent

Production considerations

Interview question

Your push is rejected as non-fast-forward. How do you fix it?

Stuck on something else?
Ask the community or search the full course.

Ask a question