Git 设置代理

Git 传输分两种协议,SSH和 http(s),设置代理也需要分两种。

http(s) 代理

Command Line

使用 命令行 模式,可以在Powershell中使用以下命令设置代理:

bash 复制代码
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"

TortoiseGit

SourceTree

SSH 代理

在目录 【C:\Users\[用户名]\.ssh】下添加一个 config 文件,并在文件中添加以下配置

bash 复制代码
Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile "C:/Users/[用户名]/.ssh/id_rsa"
  ProxyCommand connect -S 127.0.0.1:7890 -a none %h %p
  TCPKeepAlive yes

PS

虽然使用SSH,但是因为Git拉取 子模块,LFS时使用的是http传输,所以在使用ssh克隆时,如果仓库中有子模块或者LFS,也需要同时设置http代理。

相关推荐
xlq223226 分钟前
1.git
git
运维全栈笔记2 小时前
零基础掌握Jenkins CI/CD:Java项目自动构建与部署全流程指南
git·servlet·ci/cd·gitee·自动化·jenkins·devops
菜萝卜子3 小时前
【Git】GitLab 18.9 全局服务器钩子(Server Hooks)官方规范与落地实践
服务器·git·gitlab
用户11481867894844 小时前
Git Stash 丢失后的完整找回指南
前端·git
Ting.~4 小时前
GIT详解
java·笔记·git
克拉拉KLARA4 小时前
vscode禁用在git提交中插入ai coauthor copilot
git·vscode·copilot
水无痕simon5 小时前
05 Git 基础 – 查看提交历史
git
谢斯6 小时前
【GIT】子模块初始化与排错记录
git
遇见火星6 小时前
离线服务器时间同步NTP服务器配置
服务器·git·github
Soari6 小时前
Claude Code每日更新速览(v2.1.120-2026/04/27)-彻底摆脱 Git Bash,CI 级代码审查工具上线
git·ci/cd·bash·cluade code·ai for coding