Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

Why does git push get rejected with 'non-fast-forward', and what should you do?

SHORT ANSWER

The remote branch has commits you do not have, so your push would overwrite them. Pull (or fetch and rebase) first to combine the work, then push again. Do not force-push over shared work.

Explain it simply

Two people edit the same Google Doc offline. The first to save wins; the second is told to refresh and merge before saving.

Git refuses a push if it cannot simply add your commits on top of the remote history. Someone else pushed first. Fix: git pull --rebase (or git pull), resolve any conflicts, and push again. git push --force would delete their commits from the remote, which is why it is dangerous. If you rewrote your own branch on purpose, use --force-with-lease, which refuses when the remote has changed unexpectedly.

Example

bash
git push
# ! [rejected] main -> main (fetch first)
git pull --rebase
git push

What to say in the interview

"A non-fast-forward rejection means the remote has commits I lack. I pull with rebase or merge, resolve conflicts, and push again. I avoid --force on shared branches, and use --force-with-lease only on my own rewritten branches."

Common mistakes

  • Reaching for git push --force as the first fix.

#git#push#rejected

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.