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

后端 未结 12 1674
轻奢々
轻奢々 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:46

    Pull changes first:

    git pull origin branch_name
    
    0 讨论(0)
  • 2020-12-02 06:53

    This is what worked for me. It can be found in git documentation here

    If you are on your desired branch you can do this:

    git fetch origin
    # Fetches updates made to an online repository
    git merge origin YOUR_BRANCH_NAME
    # Merges updates made online with your local work
    
    0 讨论(0)
  • 2020-12-02 06:55

    Before pushing, do a git pull with rebase option. This will get the changes that you made online (in your origin) and apply them locally, then add your local changes on top of it.

    git pull --rebase
    

    Now, you can push to remote

    git push 
    

    For more information take a look at Git rebase explained and Chapter 3.6 Git Branching - Rebasing.

    0 讨论(0)
  • 2020-12-02 06:56

    (One) Solution for Netbeans 7.1: Try a pull. This will probably also fail. Now have a look into the logs (they are usually shown now in the IDE). There's one/more line saying:

    "Pull failed due to this file:"

    Search that file, delete it (make a backup before). Usually it's a .gitignore file, so you will not delete code. Redo the push. Everything should work fine now.

    0 讨论(0)
  • 2020-12-02 06:57

    Using the --rebase option worked for me.

    • git pull <remote> <branch> --rebase

    Then push to the repo.

    • git push <remote> <branch>

    E.g.

    git pull origin master --rebase

    git push origin master

    0 讨论(0)
  • 2020-12-02 06:57

    Encountered the same problem, to solve it, run the following git commands.

    • git pull {url} --rebase
    • git push --set-upstream {url} master

    You must have created the repository on github first.

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