Windows 下 git 配置代理

267次阅读
没有评论

共计 970 个字符,预计需要花费 3 分钟才能阅读完成。

Github 实在太慢,如果不配置代理几乎无法克隆仓库,于是今天几种办法都尝试了一下。

这里说明一下,由于阿蛮君本地装了代理,所以这里用的代理地址都是本地代理。

Windows 下 git 配置代理

1. 临时使用代理

这种方式仅适用于 https 方式。

git clone -c http.proxy=socks5://127.0.0.1:10808 https://github.com/username/repository.git

2. 配置全局代理

这种方式也是仅适用于 https 方式。

# 配置代理
git config --global http.proxy 'socks5://127.0.0.1:10808'
git config --global https.proxy 'socks5://127.0.0.1:10808'

# 查看代理
git config --global --get http.proxy # 查看全局代理
git config --get http.proxy # 查看当前仓库代理

# 删除代理
git config --global --unset http.proxy
git config --global --unset https.proxy

3. 配置ssh代理

由于使用 ssh 方式克隆,上面配置的全局代理方式无效,所以需要另外配置。

需要在 C:\Users\username\.ssh 下创建 config 文件,这里 username 是 windows 用户名。

config 文件内容如下:

# 这里的 -a none 是 NO-AUTH 模式,参见 https://bitbucket.org/gotoh/connect/wiki/Home 中的 More detail 一节
# 代理地址填写自己的
ProxyCommand connect -S 127.0.0.1:1080 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\username\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # 注意修改路径为你的路径
  IdentityFile "C:\Users\username\.ssh\id_rsa"
  TCPKeepAlive yes

提醒:本文发布于365天前,文中所关联的信息可能已发生改变,请知悉!

AD:【腾讯云服务器大降价】2核4G 222元/3年 1核2G 38元/年
正文完
 
阿蛮君
版权声明:本站原创文章,由 阿蛮君 2023-07-27发表,共计970字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
Copyright © 2022-2024 阿蛮君博客 湘ICP备2023001393号
本网站由 亿信互联 提供云计算服务 | 蓝易云CDN 提供安全防护和加速服务
Powered by Wordpress  Theme by Puock