[git] rejected master -> master (non-fast-forward)

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 '[email protected]: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.

This question is related to git push

The answer is


Try this, in my case it works

git rebase --abort


This is because you have made conflicting changes to its master. And your repository server is not able to tell you that with these words, so it gives this error because it is not a matter of him deal with these conflicts for you, so he asks you to do it by itself. As ?

1- git pull This will merge your code from your repository to your code of your site master. So conflicts are shown.

2- treat these manualemente conflicts.

3-

git push origin master

And presto, your problem has been resolved.


I had same as issue. I use Git Totoise. Just Right Click ->TotoiseGit -> Clean Up . Now you can push to Github It worked fine with me :D


git push -f origin master

use brute force ;-) Most likely you are trying to add a local folder that you created before creating the repo on 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


NOTICE: This is never a recommended use of git. This will overwrite changes on the remote. Only do this if you know 100% that your local changes should be pushed to the remote master.

Try this: git push -f origin master


WARNING:

Going for a 'git pull' is not ALWAYS a solution, so be carefull. You may face this problem (the one that is mentioned in the Q) if you have intentionally changed your repository history. In that case, git is confusing your history changes with new changes in your remote repo. So, you should go for a git push --force, because calling git pull will undo all of the changes you made to your history, intentionally.


this command worked well for me

git push -f origin master

You need to do

git branch

if the output is something like:

* (no branch)
master

then do

git checkout master

Make sure you do not have any pending commits as checking out will lose all non-committed changes.


i had created new repo in github and i had the same problem, but it also had problem while pulling, so this worked for me.

but this is not advised in repos that already have many codes as this could mess up everything

git push origin master --force

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

! [rejected] master -> master (non-fast-forward)

Don’t panic, this is extremely easy to fix. All you have to do is issue a pull and your branch will be fast-forward:

$ git pull myrepo master

Then retry your push and everything should be fine:

$ git push github master


I've just received this error.

I created a github repository after creating my local git repository so I needed to accept the changes into local before pushing to github. In this case the only change was the readme file created as optional step when creating github repository.

git pull https://github.com/*username*/*repository*.git master

repository URL is got from here on project github page :

enter image description here

I then re-initialised (this may not be needed)

git init
git add .
git commit -m "update"

Then push :

git push

Try this command: "git pull origin master"

It worked for me.

Check this link: https://help.github.com/articles/dealing-with-non-fast-forward-errors


This happened to me when I was on develop branch and my master branch is not with latest update.

So when I tried to git push from develop branch I had that error.

I fixed it by switching to master branch, git pull, then go back to develop branch and git push.

$ git fetch && git checkout master
$ git pull
$ git fetch && git checkout develop
$ git push

This is because you did some changes in your master so the project ask you to pull first. If you want to push it anyway you can use brute force by typing this:

git push -f origin master

Remember to first commit your changes:

git add .
git commit -m "Your commit message"

use this command:

git pull --allow-unrelated-histories <nick name of repository> <branch name>

like:

git pull --allow-unrelated-histories origin master

this error occurs when projects don't have any common ancestor.


I had this problem on a development machine. The dev branch was pushing fine but the the master branch gave me (while git pushing when being on the dev branch):

! [rejected]        master -> master (non-fast-forward)

So I tried:

git checkout master
git pull

Which gave me:

You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either.

I found out the master branch was missing from .git/config and added:

[branch "master"]
    remote = origin
    merge = refs/heads/master

Afterwards git push also worked fine on the dev branch.


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*

The only i was able to resolve this issue was to delete the local and git repo and create the same again at both ends. Works fine for now.


If git pull does not help, then probably you have pushed your changes (A) and after that had used git commit --amend to add some more changes (B). Therefore, git thinks that you can lose the history - it interprets B as a different commit despite it contains all changes from A.

             B
            /
        ---X---A

If nobody changes the repo after A, then you can do git push --force.

However, if there are changes after A from other person:

             B
            /
        ---X---A---C

then you must rebase that persons changes from A to B (C->D).

             B---D
            /
        ---X---A---C

or fix the problem manually. I didn't think how to do that yet.