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代理。

相关推荐
恋喵大鲤鱼5 小时前
git checkout
git·git checkout
知识汲取者7 小时前
Git撤销操作全解析:revert、undo与drop commit的区别与应用
git
cxxx1712 小时前
【同步Overleaf, Github】
git·overleaf
染翰13 小时前
Linux root用户安装配置Git
linux·git·后端
老虎海子13 小时前
从零手搓一个 AI 编程助手:Mini Claude Code 完全指南
人工智能·git·vscode·python·github
Cat_Rocky14 小时前
CICD-Git简单学习 操作流程后续补
git·学习
存在的五月雨14 小时前
Git的操作
git
丶Darling.14 小时前
Git 初学者使用手册
git
乐于分享的阿乐16 小时前
Git下载安装与零基础使用完整教程
git
东北甜妹16 小时前
DevOps 和 Git,Gitlab
git·gitlab·devops