用Git将本地文件push到远程github网站的过程中踩的坑

之前一直把代码存在D盘里,结果D盘突然坏了,导致代码丢失。痛定思痛,决定及时将本地代码同步到github上。
本文的操作步骤参考使用Git将本地文件提交到远程仓库,详情请点击链接,本文只记录一些坑。

简要的操作步骤如下:(注:命令行操作都在Git bash中进行。)

git init # 1.将项目文件夹初始化为git仓库
git add . # 2.把文件添加到暂存区
git commit -m 'first commit' # 3.把文件提交到仓库,引号内为说明内容
git remote add origin 你的远程库地址 # 4.关联到远程库
git pull --rebase origin master # 5.获取远程库与本地同步合并
git push -u origin master # 6.把本地库的内容推送到远程

1.fatal: couldn’t find remote ref master

$ git pull --rebase origin master
fatal: couldn't find remote ref master

解决办法:执行以下命令

$ git pull --rebase origin main

2.Merge conflict

$ git pull --rebase origin main
From https://github.com/xxx/xxx
 * branch            main       -> FETCH_HEAD
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
error: could not apply 67749e6... first commit

解决办法:删除冲突文件

$ git rm README.md
rm 'README.md'

3.OpenSSL SSL_read: Connection was reset, errno 10054

$ git push -u origin master
fatal: unable to access 'https://github.com/xxx/xxx.git/': OpenSSL SSL_read: Connection was reset, errno 10054

解决办法:执行以下命令

$ git config --global http.sslVerify "false"

4.Failed to connect to github.com port 443:connection timed out
解决办法:执行以下命令

git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy

5.The requested URL returned error: 403

$ git push -u origin master
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcm/tlsverify for more information.
remote: Permission to xxx/xxx.git denied to xxx.
fatal: unable to access 'https://github.com/xxx/xxx.git/': The requested URL returned error: 403

解决办法:
网上一般方法是更改windows用户凭据git使用git push 命令跳出remote: Permission to A denied to B的问题
但是我没有看到github凭据,后来发现问题出在第四步关联到远程库,远程库的网址应选择SSH而不是HTTPS。在这里插入图片描述
如果填错了地址,更改方法为:

$ git remote rm origin
$ git remote add origin git@github.com:xxx.git

!注意:如果反复出现10054、443和403error,首先检查是否在Git bash里面操作,然后检查远程库的地址。

6.fatal: Could not read from remote repository.

$ git push -u origin master
The authenticity of host 'github.com (140.82.112.3)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

解决办法:这是因为github没有设置SSH公钥,按照教程操作即可。

  • 7
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值