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:
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.
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
If anyone has this error while trying to push to heroku then just replace 'origin' with 'heroku' like this: git push -f heroku master
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.
this command worked well for me
git push -f origin master
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.