Git push rejected? Fix ‘updates were rejected’ safely
Short answer: Git rejects a push when the branch on the remote has commits your copy doesn't have, usually because a colleague, a merged pull request or an automated tool pushed first. Pushing anyway would throw their work away, so Git refuses by default. Fetch the new commits, combine them with yours using git pull --rebase or a regular merge, resolve any conflicts, and push again. Only force-push when you deliberately want to replace history, such as after amending your own unshared commit, and then prefer --force-with-lease.
What the message means
The wording varies by Git version and hosting service, but it's usually along the lines of "Updates were rejected because the remote contains work that you do not have locally" or "rejected ... (non-fast-forward)".
Git's push documentation explains the idea with a simple picture. You and a colleague both start from commit X. They build commit A and push it. You build commit B locally. The remote branch now points at A, and your B isn't built on top of A. Updating the branch from A to B wouldn't be a "fast-forward", because A's changes would be lost. Git's docs say the command doesn't allow such an update by default, precisely to prevent that loss of history.
Common ways it happens
- A colleague pushed to the same branch while you were working.
- A pull request was merged into
mainon the hosting site, and you're pushing tomainfrom an older local copy. - An automated process, such as a version bump or changelog bot, pushed a commit.
- You amended or rebased a commit you had already pushed.
- You're working from two machines and pushed from the other one.
The fix: bring in their work, then push
Git's documentation describes two ways to combine both histories.
Merge. git pull fetches the remote commits and creates a merge commit joining both lines of work. Pushing that merge is a fast-forward, so it's accepted.
Rebase. git pull --rebase replays your local commits on top of the remote's latest commit, giving a straight line of history without a merge commit. Then push.
Many teams prefer rebasing small local work for a cleaner history, and merging when integrating larger branches. Either way, test the combined result before pushing.
Why plain git pull sometimes refuses too
Recent Git versions stop and ask you to choose when histories have diverged. The pull documentation says --ff-only is the default when no method for reconciling divergent histories has been configured: it only updates if your branch hasn't diverged, and fails otherwise.
To set a default, configure pull.rebase (true for rebasing, false for merging) or pull.ff. Pick one for your team and document it, so everyone gets consistent history.
Handling conflicts
If both of you changed the same lines, Git stops and marks the conflicts in the files. Edit them to the correct combined version, mark them resolved by staging the files, and continue the rebase or complete the merge.
The pull documentation notes you can safely back out with git rebase --abort or git merge --abort if you don't want to deal with the conflict right now. Nothing is lost; you're back where you started.
When force-pushing is right
There's one legitimate case Git's docs describe: you pushed commit A, then amended it to B and tried to push again. Git rejects it because B doesn't build on A. If you're certain nobody has fetched and built on your earlier commit, you can overwrite it. In the documentation's words, --force is reserved for when you do mean to lose history.
Prefer --force-with-lease. According to the push documentation, it protects the remote branch by requiring its current value to match what your local copy last saw. If someone pushed in the meantime, the force-push is refused instead of silently erasing their work.
Never force-push to shared branches like main without team agreement. Many teams protect those branches on the hosting site so force-pushes are blocked entirely.
Habits that reduce rejections
- Pull before you start work and before you push.
- Work on short-lived feature branches instead of committing directly to
main. - Merge through pull requests, so the hosting site handles integration.
- Keep automated commits off busy branches, or have tools push to their own branch.
- Commit and push small changes often, so divergence stays small.
Check what you're about to push
Before pushing after a rebase or merge, look at the log of commits that will go to the remote, and run the project's tests or build. A quick look catches accidental merge commits, leftover conflict markers and commits meant for another branch.
Be careful with rebasing shared work
The pull documentation warns that rebasing rewrites history, which causes problems for commits you've already published. Rebasing your own unpushed commits onto the latest remote is safe. Rebasing commits others have already pulled forces them to recover and should be avoided.
An illustrative example
A web agency in Perth has two developers updating a client's site on the main branch. One pushes a fix to the booking form; the other, working on menu changes, gets "updates were rejected". They run git pull --rebase, resolve a small conflict in the shared stylesheet, run the site locally to check both changes, and push. The team then sets pull.rebase to true on both machines and agrees to use feature branches and pull requests from the next week.
FAQ
Is it safe to just force-push?
Only for your own unshared work, and preferably with --force-with-lease.
Does git pull --rebase change my commits?
It creates new versions of your local commits on top of the latest remote work. Their content stays the same apart from conflict fixes.
Why does this happen on my own branch?
Usually because you amended or rebased after pushing, or pushed from another machine.
Can I check what's on the remote first?
Yes. Run git fetch, then compare your branch with the remote branch in the log.
If your team keeps tripping over rejected pushes and conflicts, tell us how you work with branches today.