**背景:**本地git配置信息为本人的信息,但因为需要需要上传代码到公共github账号
①本地git init 完毕后是master,远程仓库是main,error: failed to push some refs to ‘github-teacher:NetworkCommunication/CachOf.git’
②:host文件配置错误导致:
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
和
kex_exchange_identification: banner line contains invalid characters
banner exchange: Connection to 151.101.1.194 port 443: invalid format
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
③repository已经存在项目且不是你本人提交
error: failed to push some refs to ‘github-teacher:NetworkCommunication/CachOf.git’
解决参考:https://blog.csdn.net/kiddd_fu/article/details/78247290
参考https://blog.csdn.net/komojay/article/details/80480098
cd ~/.ssh
ssh-keygen -t rsa -C "XXXXXXXX"
然后会提示
Enter file in which to save the key (/Users/zhengrunming/.ssh/id_rsa):
这里我输入id_rsa_teacher。
创建完成如下:
id_rsa_teacher.pub是公钥,id_rsa_teacher是私钥,打开id_rsa_teacher.pub公钥,把里面的内容拷贝到github账户中的ssh key中。
更改config文件,如下,new_github是我新增加的文件。
如上步骤完成后第一步就完成了。
第二步:
在一个空文件夹下使用命令如下
git init
git commit -m "first commit"
git branch -M main
git remote add origin xxx //xxx为你要上传的的git仓库地址
git push -u origin main
第三步:
第一个错误使用命令
git branch -m master main
第二个错误正确配置config即可解决
第三个错误使用命令
git pull origin main --allow-unrelated-histories
Note:
//github-teacher替换仓库地址:github.com
//因为github-teacher为我们新配置的github host相关的信息
git remote add origin git@github-teacher:NetworkCommunication/test.git