GitHub 上创建了 readme.md 时提交到远程报错,附上解决方案

在github上新建仓库勾选了创建 README.md 时,如果根据教程中推送到远程会报错如下:

vagrant@homestead:~/Code/Laravel$ git push -u origin master
To git@github.com:xxx/hello_laravel.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:xxx/hello_laravel.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

因为github上的版本和本地版本会产生冲突,可以加上 -f 参数强制提交:

git push -u origin master -f
好看的脸蛋,一米六七
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 3
Epona

常规操作应该是

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

或者

$ git pull
$ git push
7年前 评论

@Epona 嗯,fetch是将远程代码拉下来?如果把远程代码拉下来就覆盖掉本地的了。

7年前 评论
Epona

@LiLiKiLL fetch是获取远程的信息, pull 才是拉下来, 以及,善用rebase?

7年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!