Error pushing to GitHub using Git for Windows

前端 未结 2 1752
不思量自难忘°
不思量自难忘° 2021-01-28 15:22

I have created a Git repository on GitHub, and a local repository too. First I pulled the remote repository into the local one. Then I added a file, staged the file, committed i

相关标签:
2条回答
  • 2021-01-28 15:47

    The remote repo is not empty; it contains a README that you probably created through the GitHub web interface. You have to pull it before you can push to it:

    git pull --rebase origin master
    git push
    

    (The --rebase is not strictly necessary but avoids an ugly merge commit.)

    0 讨论(0)
  • 2021-01-28 15:57

    A non-fast-forward push means the remote master is not an ancestor of your local master. Git is refusing the push as a safety mechanism to prevent destroying work.

    The output of git log --graph --decorate --pretty=oneline --abbrev-commit --all will give you a graphical depiction of your repository’s history. If you are sure you don’t mind replacing or destroying what is in GitHub, run

    $ git push --force origin master
    

    The --force option is documented as (with added emphasis)

    -f, --force
    Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it. This flag disables the check. This can cause the remote repository to lose commits; use it with care.

    To keep what is there, you will need to rebase your local master on top of the one on GitHub and then push the result.

    $ git fetch
    $ git rebase origin/master master
    $ git push origin master
    

    or just

    $ git checkout master
    $ git pull --rebase
    

    The sequence above is the sunny-day case. You may need to resolve conflicts, but that seems unlikely given your description.

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