问题描述
我创建了一个 Visual Studio Code development container。一切正常,这是一项非常酷的技术,但它无法将我提交的代码推送到外部 Git 服务器。我正在尝试推送到 BitBucket,但问题与 GitHub 相同。
当我尝试从终端推送时,收到此错误消息:
$ git push
ssh: connect to host bitbucket.org port 22: Cannot assign requested address
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
当我尝试使用 VSCode Git 选项卡命令推送时,错误更完整:
Please make sure you have the correct access rights
and the repository exists.
> git ls-tree -l HEAD -- /workspaces/xxxx/.devcontainer/Dockerfile
> git show --textconv HEAD:.devcontainer/Dockerfile
> git push origin master:master
ssh: connect to host bitbucket.org port 22: Cannot assign requested address
fatal: Could not read from remote repository.
如果我在本地重新打开我的工作区,推送会照常进行。
我以为这个配置是自动的。我的远程存储库是使用 ssh 连接的。
我必须配置什么才能推送我的代码?
解决方法
哎呀!错误的问题。看起来我的 ISP 决定阻止我到端口 22 的出站连接。啊!!!没想到。
我发现 GitHub 和 BitBucket 对神经质的系统管理员都有clever workarounds。
只需将这些配置添加到您的 ~/.ssh/config
文件中,并通过不可阻止的 https 端口 443 建立与外部 Git 服务器的 ssh 连接:
Host github.com
Hostname ssh.github.com
Port 443
Host bitbucket.org
Hostname altssh.bitbucket.org
Port 443
以下是使用 VSCode 时 sharing your ssh credentials 与容器的一些额外提示。
,我的猜测是您需要转发 Docker 容器的端口。
左下角应该是这样的link to Image
点击没有 Ports Forwarded 的那个(右一个),然后点击 10 个转发端口 22。