rejected master - master non-fast-forward
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
rejected master -> master (non-fast-forward) means the remote branch has commits that your local branch does not contain. Git refuses the push because accepting it would overwrite remote history instead of moving the remote pointer forward safely.
What a Fast-Forward Push Means
A fast-forward push is possible only when your local branch is a direct descendant of the remote branch. In that situation, Git can move the remote reference from the old commit to your newer commit without losing anything.
A non-fast-forward rejection means the histories diverged. That usually happens because:
- someone else pushed to the branch first
- you rebased or amended locally
- you are pushing from an outdated clone
Inspect the Branch State First
Do not guess. Fetch the latest remote state and inspect the graph.
This quickly shows whether the remote has one or more commits you need to integrate.
Usual Fix: Rebase or Merge the Remote Changes
If you want a clean linear history, rebase your work onto the updated remote branch.
Resolve any conflicts, then continue:
After the rebase succeeds, push again:
If your team prefers merge commits, merge instead of rebasing:
Both approaches are valid. The right one depends on your branch policy.
When --force-with-lease Is Appropriate
If you intentionally rewrote your local history, such as after an interactive rebase, a normal push may still fail even after fetching. In that case, you may need to replace the remote history.
The safer force option is:
--force-with-lease checks that the remote branch still points to the commit you expect before overwriting it. That makes it much safer than raw --force.
Use it only when rewriting remote history is actually acceptable for that branch. On shared master or main, many teams prohibit it entirely.
Typical Team Workflow to Avoid the Error
The easiest prevention strategy is:
- fetch or pull before starting new work on a shared branch
- do development on feature branches, not directly on
master - merge through pull requests
- keep the shared branch protected from history rewrites
When teams work directly on the release branch without frequent sync, non-fast-forward rejections become normal and disruptive.
Example Recovery Scenario
Suppose your local master has commit C, but origin/master moved from A to B because a teammate pushed. Your push is rejected because Git would have to drop B to place C directly on the remote.
The correct fix is to integrate B first, producing either a rebased C' on top of B or a merge commit that combines both histories. After that, the push becomes a normal fast-forward update again.
Common Pitfalls
The biggest mistake is reaching for git push --force immediately on a shared branch. That can erase teammates' work.
Another mistake is running git pull without understanding whether it merges or rebases in your configuration. If you care about history shape, be explicit.
People also often resolve the rejection locally but forget to inspect what changed on the remote. The remote commits may include schema changes, generated files, or deployment updates that deserve review before integration.
Finally, do not treat master as a scratch branch. Protected branches work best when day-to-day development happens elsewhere.
Summary
- A non-fast-forward rejection means the remote branch contains commits your local branch does not have.
- Fetch first and inspect the history before trying random commands.
- Rebase or merge the remote branch into your local work, then push again.
- Use
--force-with-leaseonly when history rewrite is intentional and allowed. - Feature-branch workflows reduce the frequency of this error on shared branches.
Related reading
- Remote branch is not showing up in git branch -r
- Remote Git branches not visible
- Remote origin already exists on 'git push' to a new repository
- Remove a file from a Git repository without deleting it from the local filesystem
- Remove a folder from git tracking
- Remove a git commit which has not been pushed
- Remove a git commit which has not been pushed
- Remove credentials from Git
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.