Git push failed, “Non-fast forward updates were rejected”

后端 未结 12 1675
轻奢々
轻奢々 2020-12-02 06:12

I\'ve edited my GIT repositories via Git Online. After I tried to push my local code changes, I got an error:

Git push failed, To prevent from losing histor         


        
相关标签:
12条回答
  • 2020-12-02 06:58

    I encountered the same error, just add "--force" to the command, it works

    git push origin master --force
    
    0 讨论(0)
  • 2020-12-02 07:01

    I've hade the same problem. I resolved with

    git checkout <name branch>
    git pull origin <name branch>
    git push origin <name branch>
    
    0 讨论(0)
  • 2020-12-02 07:03

    You can add --force-with-lease to the command, it will works.

    git push --force-with-lease
    

    --force is destructive because it unconditionally overwrites the remote repository with whatever you have locally. But --force-with-lease ensure you don't overwrite other's work.

    See more info here.

    0 讨论(0)
  • 2020-12-02 07:04

    Add --force to your command line if you are sure you want to push. E.g. use git push origin --force (I recommend the command line as you will find much more support from other users with the command line. Also this may not be possible with SmartGit.) See this site for more information: http://help.github.com/remotes/

    0 讨论(0)
  • 2020-12-02 07:09

    Sometimes, while taking a pull from your git, the HEAD gets detached. You can check this by entering the command:

    git branch 
    
    • (HEAD detached from 8790704)

      master

      develop

    It's better to move to your branch and take a fresh pull from your respective branch.

    git checkout develop
    
    git pull origin develop
    
    git push origin develop
    
    0 讨论(0)
  • 2020-12-02 07:13

    I've had the same problem.
    The reason was, that my local branch had somehow lost the tracking to the remote counterpart.

    After

    git branch branch_name --set-upstream-to=origin/branch_name
    git pull
    

    and resolving the merging conflicts, I was able to push.

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