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

相关推荐
拾-光8 小时前
【Git】命令大全:从入门到高手,100 个最常用命令速查(2026 版)
java·大数据·人工智能·git·python·elasticsearch·设计模式
Snooker_14612 小时前
TRAE、VSCode上进行git管理
ide·git·vscode
zincsweet14 小时前
Git开发工具教程
git
yuyuyui14 小时前
Git实战覆盖98%日常开发场景
git
Eloudy17 小时前
git clone --mirror 同步桥
大数据·git
cxwl3sxl17 小时前
重装系统后GIT仓库修复
git
OYangxf17 小时前
Git速查命令
大数据·git·elasticsearch
OYangxf17 小时前
Git Common Errors
大数据·git·elasticsearch
Mike_66618 小时前
git@gitlab-rdc.xxxxx.com: Permission denied (publickey).fatal: 无法读取远程仓库。
git·elasticsearch·gitlab
zh路西法18 小时前
【git一键push脚本】基于Windows bat脚本的一键git提交脚本
windows·git·elasticsearch