Skip to content

Push Rejected

Error message

                ! [rejected] main -> main (fetch first)
              

Quick summary

Your push was rejected because the remote branch has newer commits — you need to pull and integrate them first.

Why this happens

  • Someone else pushed commits to the remote that you don't have locally

  • Your local branch is behind the remote branch

  • Force push is disabled on the remote branch (e.g., protected main)

Minimal example

✗ Broken code
git push  # ! [rejected] main -> main (fetch first)
✓ Fixed code
git pull --rebase
git push  # now succeeds

The remote has commits you don't have — git pull --rebase integrates them first, then git push succeeds.

How to diagnose

  • Run git status — does it say your branch is behind the remote?

  • Run git fetch to download remote changes without merging

  • Check git log origin/main..main to see how your local commits differ

How to fix

  • Run git pull (or git pull --rebase) to integrate remote changes

  • Resolve any merge conflicts that arise from the pull

  • Run git push again after the pull succeeds

How to prevent

  • Pull before you push to stay in sync with the remote

  • Push frequently in small increments to avoid large divergences

Related Resources

Related Glossary

Related Lessons

Related Practice

← Back to language