Dealing with “Non-fast forward updates were rejected” error in Git

If your attempt of pushing local changes in your local working copy of a Git repository to remote server fails with “Non-fast forward updates were rejected”, there are several things you my try to fix it. Here I give you some advises, but read comments around them throughly, as without being sure, what you’re doing, you may do some charm to your local working copy or even remote repository.

First, try pulling changes first. Either using command line (git pull origin [branch_name]) or in Netbeans (Team > Git > Remote > Pull). It was reported that pulling with Netbeans sometime fails, while using command line in the same time and for the same repostory works and solves the problem. If both methods fail, you should get logs with information, which local file is possible source of the problem. Consider, if you can delete it (and get current version from remote) — of course, only if you did not made any changes to this file — or edit it and fix problematic lines.

Another option is to do a git pull with rebase option before pushing:

git pull --rebase

This will get the changes that you made online (in your origin) and apply them locally, then add your local changes on top of it.

Or, if you’re sure, that your local changes are bug-free and most up-to-date, you can add --force switch to your command line.

Other resources, where you should find more information or help:

Leave a Reply