Error Encyclopedia

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

1

Someone else pushed to the same branch since your last pull

2

You made commits on a different machine without pulling first

3

You rebased or amended commits that were already pushed (force push needed)

4

Remote branch is protected and you do not have push permissions

5

Remote deleted commits (e.g., force push by another contributor)

6

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

❌ Before
$ git push origin main
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs
✅ After
$ 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:

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.