【问题日志】本地初始化git仓库,设置远程仓库地址,提交代码出现错误

原因分析

由于我是直接在本地创建文件夹并且初始化仓库,进而再去GitHub下创建仓库。并在本地仓库下关联远程仓库。

基于以上操作

遇到问题代码如下:

To git@https://github.com/DoyoudoLove/vuetest.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@https://github.com/DoyoudoLove/vuetest.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushin
hint: to the same ref. You may want to first merge the remote changes (e.g.
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

使用 git push -f无果

其次
    git pull
    git branch --set-upstream-to=origin/<branch> master
  将本地的分支和远程分支进行关联

出现报错 fatal: refusing to merge unrelated histories
使用
    git pull origin master --allow-unrelated-histories
  把两段不相干的 分支进行强行合并。

总结

以后还是乖乖的先在 GitHub 上建立好仓库,再在本地上克隆下来提交吧。


参考文章

git Updates were rejected because the remote contains work that you do 解决办法
git 出现 fatal: refusing to merge unrelated histories 错误
git提交远程报错[rejected] master -> master (fetch first)

last update time 2022-02-26