Github同步本地分支时报错,无法使用VSCode将本地版本同步到Github
尽管我已经在Github网站配置了SSH公钥,仍然无法同步本地分支。
报错信息:
fatal: unable to access 'https://github.com/xxx.git/': Failed to connect to github.com port 443 after 75007 ms: Couldn't connect to server
解决方法:将git config中的remote.github.url从http url改成ssh url
查看git config
> git config --list
...
remote.github.url=https://github.com/xxx.git
remote.github.fetch=+refs/heads/*:refs/remotes/github/*
branch.main.remote=github
branch.main.merge=refs/heads/main
修改remote url
复制Github上对应仓库的ssh路径,使用下面命令修改
> git remote set-url github git@github.com:xxx.git
> git config --list
...
remote.github.url=git@github.com:xxx.git
remote.github.fetch=+refs/heads/*:refs/remotes/github/*
branch.main.remote=github
branch.main.merge=refs/heads/main
可以看到remote.github.url已经修改为ssh路径,再次同步就成功了
(这里的github是远程存储库名称,按照自己的设置,通常设置为github或origin)