Failed to Push to Remote Repository
Fix 'failed to push some refs' and 'rejected' errors when pushing to Git remotes. Learn common causes and solutions.
What Does This Error Mean?
The 'failed to push some refs' error means Git rejected your push because the remote branch contains commits that you do not have locally. Git will not allow a push that would overwrite commits on the remote — you must first integrate the remote changes into your local branch.
Common Causes
Someone else pushed to the same branch since your last pull
You made commits on a different machine without pulling first
You rebased or amended commits that were already pushed (force push needed)
Remote branch is protected and you do not have push permissions
Remote deleted commits (e.g., force push by another contributor)
Branch name mismatch between local and remote
How to Fix It
Pull before pushing
Fetch remote changes and merge them into your local branch first.
# Pull with merge (default) git pull origin main # Pull with rebase (cleaner history) git pull --rebase origin main # Then push git push origin main
Force push with caution
Use force push only when you are sure you want to overwrite remote history.
# Standard force push (may overwrite others work) git push --force origin main # Safer: force with lease (fails if remote has new commits) git push --force-with-lease origin main # Verify before force push git log --oneline origin/main..main
Check remote status
View the remote branch state to understand what is different.
# Fetch and compare git fetch origin git log --oneline HEAD..origin/main # Commits in remote not in local git log --oneline origin/main..HEAD # Commits in local not in remote # See the full diff git diff HEAD origin/main
Before & After Examples
$ git push origin main ! [rejected] main -> main (non-fast-forward) error: failed to push some refs
$ git pull --rebase origin main $ git push origin main Everything up-to-date
Related Tools
Use these tools to debug and fix this error:
Related Errors
Other common errors in this category:
Git Merge Conflict
Learn how to resolve git merge conflicts. Understand conflict markers, use merge tools, and prevent conflicts in collaborative development.
Detached HEAD State
Fix detached HEAD state in Git. Learn what it means, how to avoid losing work, and how to reattach your HEAD to a branch.
Frequently Asked Questions
What is a non-fast-forward rejection?
It means the remote branch has commits you don't have locally. Git cannot fast-forward your local branch to match the remote because your histories have diverged. You must merge or rebase first.
When is force push acceptable?
Force push is acceptable on personal feature branches, after a rebase to clean up history, or when fixing a sensitive commit (like accidentally committed secrets). Never force push to shared branches like main or develop without team coordination.