rejected master -> master (non-fast-forward)

Viewed 459047

I'm trying to push my project (all files in a new repository). I follow the steps but when I push with git push -u origin master I get this error:

! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:asantoya/projectnewbies.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again.  See the
'Note about fast-forwards' section of 'git push --help' for details.

I got this error many times and can't figure out what to do.

22 Answers

My Remote was not in sync with the local so this worked for me

git pull --rebase

and make sure when you do git pull again it should say Already up to date and now you are ready to push to origin

assuming you have already git remote add origin remote repository URL

do

git push origin master

The Screenshot says it all enter image description here

Alternatively you can do this

  1. git stash (stores uncommited work temporarily)
  2. git pull (make your local and remote in sync)
  3. git stash pop (get back you uncommited changes )
  4. git push

This may also be caused due to some name error caused while giving name to the Repo. If any of the above answers haven't worked .This worked for me:

Delete that repo and create a new one and try the following commands again:

cd 'Local Directory Path'
git remote add origin *your_git_name.git*
git push -u origin master

if add origin shows already exists use this instead:

git remote set-url origin *your_git_name.git*

If anyone has this error while trying to push to heroku then just replace 'origin' with 'heroku' like this: git push -f heroku master

Try this, in my case it works

git rebase --abort

I also got the same error but I solved it easily by fetching its URLs as

git fetch origin Your repository origin

then simply applying the command

git push -f origin master

You will get a good result

This means that your remote git repository is configured with denyNonFastforwards = true. Although dangerous, sometimes you might really need to overwrite the git history (e.g. after running bfg --strip-blobs-bigger-than 100M) thus you can temporarily modify that setting to false (denyNonFastforwards = true, see it in your-repository.git/config) then forcibly push (i.e. git push -f).

Related