寫在前面
自己的測試環(huán)境:Ubuntu20.04
下面的操作都是和 git
有關(guān),所以針對不同的操作系統(tǒng)(比如 Windows)也是一樣的。
一、問題描述
在此之前使用git
執(zhí)行 git push origin master
的命令時,能夠正常執(zhí)行,但是一段時間之后,再次執(zhí)行該命令,出現(xiàn)了如下問題:
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.
二、解決方法
出現(xiàn)這種情況后, 自己重新生成了ssh key
,并且把id_rsa.pub
中的內(nèi)容復(fù)制到了 github
的SSH keys
中,但是依舊沒能實(shí)現(xiàn)想要的效果。根據(jù)當(dāng)前終端的報錯信息ssh: connect to host github.com port 22: Connection timed out
以及通過查閱其他資源,可能是當(dāng)前的網(wǎng)絡(luò)環(huán)境禁用了port 22
,因此切換到https
傳輸, 進(jìn)行上傳。
具體操作:
- 打開
- 修改
url = git@github.com:用戶名/倉庫名.git
修改為
url = https://用戶名@github.com/用戶名/倉庫名.git
然后退出。
再次執(zhí)行 push
.
這次可能會提示輸入密碼,需要輸入自己的 token
碼,才能成功。
如果不知道自己的token
碼,需要登錄自己的github --> setting --> Developer Settings --> Personal access tokens
進(jìn)行設(shè)置。具體可以參考鏈接[4]。文章來源:http://www.zghlxwxcb.cn/news/detail-814202.html
參考鏈接
[1] 凌煙閣主5221. git可以add,pull, 不可以push的問題解決 [EB/OL]. https://www.jianshu.com/p/25933a149307, 2019-06-21/2024-01-21.
[2] tom_wong666. 【問題探討】瀏覽器可以訪問github項(xiàng)目,但是git clone失敗 [EB/OL]. https://blog.csdn.net/tom_wong666/article/details/128961438, 2023-02-09/2024-01-21.
[3] 生信編程日常. github 訪問ping不通的解決辦法 [EB/OL]. https://www.jianshu.com/p/2da7fa4d7fba, 2020-08-16/2024-01-21.
[4] github訪問令牌token的創(chuàng)建方法 [EB/OL]. https://zhuanlan.zhihu.com/p/501872439, 2023-05-06/2024-01-21.文章來源地址http://www.zghlxwxcb.cn/news/detail-814202.html
到了這里,關(guān)于Ubuntu 使用 git 能夠 clone 但不能 push 的參考解決方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!