git项目初次push提示error: failed to push some refs to https://gitee.com/xxxx/gittest.git’解决方案 --九五小庞(代码片段

Posted 九五小庞

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git项目初次push提示error: failed to push some refs to https://gitee.com/xxxx/gittest.git’解决方案 --九五小庞(代码片段相关的知识,希望对你有一定的参考价值。

在本地与远程新建仓库并关联后,初次push可能会遇到以下问题

  1. $ git push -u origin master
  2. To https://gitee.com/xxxx/gittest.git
  3. ! [rejected] master -> master (fetch first)
  4. error: failed to push some refs to \'https://gitee.com/xxxx/gittest.git\'
  5. hint: Updates were rejected because the remote contains work that you do
  6. hint: not have locally. This is usually caused by another repository pushing
  7. hint: to the same ref. You may want to first integrate the remote changes
  8. hint: (e.g., \'git pull ...\') before pushing again.
  9. hint: See the \'Note about fast-forwards\' in \'git push --help\' for details.

原因是因为远程仓库有一些文件而本地没有,通常是在远程建立仓库时有一些初始化文件比如Readme License 等,并且直接pull会提示warning: no common commits,对于此类问题可以采用两种解决办法

1.git push -f 强制将本地文件推送至远程,这样会将远程仓库的已有的文件清掉

2. git pull origin master –allow-unrelated-histories 使用此命令告诉 git 允许不相关历史合并 这样就能把远程文件拉取回来。执行此命令后会有一个提示,要求说明为何要讲两个不相关的分支合并,输入信息后保存即可。

拉取完不同的文件之后再执行git push -u origin master命令即可push成功。

建议使用第二种办法

  1. Merge branch \'master\' of https://gitee.com/xxxx/gittest.git
  2. # Please enter a commit message to explain why this merge is necessary,
  3. # especially if it merges an updated upstream into a topic branch.
  4. #
  5. # Lines starting with \'#\' will be ignored, and an empty message aborts
  6. # the commit.
  7. Merge made by the \'recursive\' strategy.
  8. .gitignore | 66 ++++++++++++
  9. LICENSE | 339 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  10. README.en.md | 36 +++++++
  11. README.md | 37 +++++++
  12. 4 files changed, 478 insertions(+)
  13. create mode 100644 .gitignore
  14. create mode 100644 LICENSE
  15. create mode 100644 README.en.md
  16. create mode 100644 README.md

以上是关于git项目初次push提示error: failed to push some refs to https://gitee.com/xxxx/gittest.git’解决方案 --九五小庞(代码片段的主要内容,如果未能解决你的问题,请参考以下文章

git push origin master出错:error: failed to push some refs to

git 错误error: failed to push some refs to

git常见错误:error: failed to push some refs to 'xxx'

error: failed to push some refs to git的解决办法

解决git push出现error: failed to push some refs to 错误

git push报错:error: RPC failed; result=22, HTTP code = 413