oCodeHoney's BLOG

【Git】github直接连接已有项目出现的问题

字数统计: 301阅读时长: 1 min
2020/06/09 Share

以前在连接远程仓库的时候都是是先clone一个本地新仓库再把文件复制过去,这次感觉太麻烦,想把创建完的项目直接连接到仓库,然后就error了。

参考

错误代码

error: failed to push some refs to 'https://github.com/xxxxxx.git'

解决方案

因为在那之前我进行了多次尝试,所以可能会报这个错fatal: remote origin already exists.
所以首先需要断开之前的连接:

git remote rm origin

然后连接:

1
2
git remote add origin https://github.com/xxxxxx.git
git push -u origin master

这个时候就会报前面说的错误了 error: failed to push some refs to 'https://github.com/xxxxxx.git'

一开始我先尝试 git pull origin master 了一次再push还是报错,错误原因我自己分析了一下还是因为文件冲突了,但是为什么pull了没用还是暂时没有想清楚,所以没办法只能强制push:

git push -u origin master -f

这样就没有报错了,然后依次add,commit,push就成功了。


Author:oCodeHoney

Date:2020-6-9


CATALOG
  1. 1. 参考
  2. 2. 错误代码
  3. 3. 解决方案