How to Fix: failed to push some refs
Diagnose non-fast-forward pushes, fetch remote work safely, integrate it, and retry without reaching immediately for a destructive force push.
failed to push some refs is a summary, not the root cause. Read the lines immediately above it. A common reason is a non-fast-forward rejection: the remote branch contains commits your local branch does not have.
Inspect the divergence
Preserve local changes first by committing them or using a named stash. Then fetch without merging:
git status --short --branch
git fetch origin
git log --oneline --graph --decorate --all -20
Fetching is a useful diagnostic because it updates remote-tracking refs without altering the current branch.
Integrate the remote work
Choose the workflow your repository expects. Merge keeps both lines of history:
git merge origin/main
git push origin main
Rebase replays your unpublished local commits on top of the remote branch:
git rebase origin/main
git push origin main
Resolve conflicts carefully, run tests, and inspect the resulting history before pushing.
Force is not the default fix
High risk:
git push --forcecan discard commits already published by someone else.
If a team-approved history rewrite is truly required, make a backup branch and prefer the guarded form:
git branch backup/before-force-push
git fetch origin
git push --force-with-lease origin main
--force-with-lease refuses to overwrite a remote value you have not observed, but it is still a history rewrite. Protected branches may reject it.
Other causes include server permissions, branch protection, pre-receive hooks, or pushing a branch that has no commits. Match the exact preceding error before choosing a fix. Compare Git fetch vs. pull for a safer sync workflow.