rejected master -> master (non-fast-forward)
Question
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.
Accepted Answer
As the error message says: git pull
before you try to git push
. Apparently your local branch is out of sync with your tracking branch.
Depending on project rules and your workflow you might also want to use git pull --rebase
.
Popular Answer
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
Read more... Read less...
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 :
I then re-initialised (this may not be needed)
git init
git add .
git commit -m "update"
Then push :
git push
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.
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.
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