git - 如何配置 Git 以从代理服务器后面的 GitHub 克隆存储库

标签 git ubuntu github ssh

我在安装 Ubuntu 时遇到了有关 GitHub 上的 Git 的问题。

我已通过 git config --global http.proxy proxyserver:port 配置了代理设置.

但是当我输入git clone <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dcbbb5a89cbbb5a8b4a9bef2bfb3b1" rel="noreferrer noopener nofollow">[email protected]</a>:myusername/example.git时,我得到以下信息:

错误:

ssh: connect to host github.com port 22: Connection timed out
fatal: The remote end hung up unexpectedly

我应该做什么?

最佳答案

我按照以下步骤从公司代理后面访问 git 存储库。此方法适用于使用 git URL 的 git 存储库,例如“git://something.git”; 对于使用 http URL(如“http://something.git ”)的 git 存储库,请使用此 link 接受的答案相反。

此版本使用 corkscrew 并设置代理所需的用户名和密码。

安装开瓶器(Ubuntu)

sudo apt-get install corkscrew

创建包含您的代理用户名和密码的凭据文件

echo "username:password" > ~/.corkscrew-auth

就我而言,凭据如下所示

domain\username:password

安全验证文件

chmod 600 ~/.corkscrew-auth

创建开瓶器包装脚本 ~/scripts/corkscrew.wrapper

#!/bin/sh
exec corkscrew PROXY_IP_ADDRESS PROXY_PORT $* ~/.corkscrew-auth

使脚本可执行

chmod +x ~/scripts/corkscrew.wrapper

配置git

git config --global core.gitproxy ~/scripts/corkscrew.wrapper

测试是否可以克隆存储库

git init
git clone git://SOME_GIT_REPOSITORY_ADDRESS

如果你想清理刚刚创建的 git 配置

git config --global --unset core.gitproxy

关于git - 如何配置 Git 以从代理服务器后面的 GitHub 克隆存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18604719/

相关文章:

git - 自动提交和增加内部版本号的脚本

linux - rc.local 内容在启动时不运行

python - 为什么子进程在这里抛出 OSError?

unit-testing - 如何在 Github 中显示我的测试通过/失败?

ruby-on-rails - Git Push Heroku Master 错误与 Rails

git - 如何在 Gitlab CI 中获取 Gitlab merge 请求描述?

git - 如何避免 Jenkins 在构建另一个分支时认为构建已修复?

python - 如何在预提交 git hook 上运行 python 包

GIT - 将最新的分支复制到另一个目录

ubuntu - 代码服务器不会在 Raspberry Pi 4 上启动