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

后端 未结 22 1906
萌比男神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:57

    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 :

    enter image description here

    I then re-initialised (this may not be needed)

    git init
    git add .
    git commit -m "update"
    

    Then push :

    git push
    
    0 讨论(0)
  • 2020-11-30 16:59

    I had same as issue. I use Git Totoise. Just Right Click ->TotoiseGit -> Clean Up . Now you can push to Github It worked fine with me :D

    0 讨论(0)
  • 2020-11-30 17:01

    You need to do

    git branch
    

    if the output is something like:

    * (no branch)
    master
    

    then do

    git checkout master
    

    Make sure you do not have any pending commits as checking out will lose all non-committed changes.

    0 讨论(0)
  • 2020-11-30 17:01

    Try this, in my case it works

    git rebase --abort

    0 讨论(0)
  • 2020-11-30 17:02

    use this command:

    git pull --allow-unrelated-histories <nick name of repository> <branch name>

    like:

    git pull --allow-unrelated-histories origin master

    this error occurs when projects don't have any common ancestor.

    0 讨论(0)
  • 2020-11-30 17:03

    My Remote was not in sync with the local so this worked for me

    git pull --rebase

    and make sure when you do git pull again it should say Already up to date and now you are ready to push to origin

    assuming you have already git remote add origin remote repository URL

    do

    `git push origin master`  
    

    The Screenshot says it all

    Alternatively you can do this

    1. git stash (stores uncommited work temporarily)
    2. git pull (make your local and remote in sync)
    3. git stash pop (get back you uncommited changes )
    4. git push
    0 讨论(0)
提交回复
热议问题