**背景:**本地git配置信息為本人的信息,但因?yàn)樾枰枰蟼鞔a到公共github賬號(hào)
整體思路
1:創(chuàng)建新的SSH KEY,并將生成的新的id_rsa文件中的公鑰添加到github對(duì)應(yīng)的sshkey,并更改本地host文件。參考博客:https://www.jianshu.com/p/12badb7e6c10 https://blog.csdn.net/komojay/article/details/80480098
2:使用git基本操作上傳
3:踩坑報(bào)錯(cuò)解決。
①本地git init 完畢后是master,遠(yuǎn)程倉庫是main,error: failed to push some refs to ‘github-teacher:NetworkCommunication/CachOf.git’
②:host文件配置錯(cuò)誤導(dǎo)致:
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已經(jīng)存在項(xiàng)目且不是你本人提交
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"
然后會(huì)提示
Enter file in which to save the key (/Users/zhengrunming/.ssh/id_rsa):
這里我輸入id_rsa_teacher。
創(chuàng)建完成如下:
id_rsa_teacher.pub是公鑰,id_rsa_teacher是私鑰,打開id_rsa_teacher.pub公鑰,把里面的內(nèi)容拷貝到github賬戶中的ssh key中。
更改config文件,如下,new_github是我新增加的文件。
如上步驟完成后第一步就完成了。
第二步:
在一個(gè)空文件夾下使用命令如下
git init
git commit -m "first commit"
git branch -M main
git remote add origin xxx //xxx為你要上傳的的git倉庫地址
git push -u origin main
第三步:
第一個(gè)錯(cuò)誤使用命令
git branch -m master main
第二個(gè)錯(cuò)誤正確配置config即可解決
第三個(gè)錯(cuò)誤使用命令文章來源:http://www.zghlxwxcb.cn/news/detail-817003.html
git pull origin main --allow-unrelated-histories
Note:文章來源地址http://www.zghlxwxcb.cn/news/detail-817003.html
//github-teacher替換倉庫地址:github.com
//因?yàn)間ithub-teacher為我們新配置的github host相關(guān)的信息
git remote add origin git@github-teacher:NetworkCommunication/test.git
到了這里,關(guān)于使用git上傳代碼到非本人賬號(hào)的的github倉庫的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!