Error pushing to GitHub using Git for Windows

前端 未结 2 1753
不思量自难忘°
不思量自难忘° 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: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.

提交回复
热议问题