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

后端 未结 22 1950
萌比男神i
萌比男神i 2020-11-30 16:13

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:



        
相关标签:
22条回答
  • 2020-11-30 16:50
    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.

    0 讨论(0)
  • 2020-11-30 16:50

    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

    0 讨论(0)
  • 2020-11-30 16:51

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

    0 讨论(0)
  • 2020-11-30 16:52

    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.

    0 讨论(0)
  • 2020-11-30 16:55

    this command worked well for me

    git push -f origin master
    
    0 讨论(0)
  • 2020-11-30 16:55

    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.

    0 讨论(0)
提交回复
热议问题