🎉 DevOps Interview Prep Bundle is live — 1000+ Q&A across 20 topicsGet it →
All Fixes
Today I Fixed

git push rejected: non-fast-forward after rebase

gitJun 21, 20265 minutes to fixgittroubleshooting

Did a git rebase main on my feature branch, then git push got rejected:

! [rejected]        feature/my-feature -> feature/my-feature (non-fast-forward)
error: failed to push some refs to 'origin'
hint: Updates were rejected because the tip of your current branch is behind its remote counterpart.

This happens because rebase rewrites commit history. My local branch and the remote branch now have diverged histories.

The fix:

bash
git push --force-with-lease

Why --force-with-lease instead of --force:

--force blindly overwrites the remote. If a teammate pushed to the same branch while I was rebasing, --force would delete their commits.

--force-with-lease checks that the remote branch is still where I last saw it. If someone else pushed, the force-push fails and I need to pull first. Much safer.

When it's safe to do this:

Only on your own feature branches. Never --force-with-lease on main or develop. On shared branches, either don't rebase (use merge), or communicate with teammates before doing it.