之前一直把代码存在D盘里,结果D盘突然坏了,导致代码丢失。痛定思痛,决定及时将本地代码同步到github上。 本文的操作步骤参考使用Git将本地文件提交到远程仓库,详情请点击链接,本文只记录一些坑。
简要的操作步骤如下:(注:命令行操作都在Git bash中进行。)
git init
git add .
git commit -m 'first commit'
git remote add origin 你的远程库地址
git pull --rebase origin master
git push -u origin master
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公钥,按照教程操作即可。
|