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
常规操作应该是
或者
@Epona 嗯,fetch是将远程代码拉下来?如果把远程代码拉下来就覆盖掉本地的了。
@LiLiKiLL fetch是获取远程的信息, pull 才是拉下来, 以及,善用rebase?