macOS 上的git代理配置在哪里

Git 的代理配置可以在三个不同的级别进行设置,每个级别对应不同的配置文件位置:

1. 系统级别配置

  • 配置文件位置/etc/gitconfig
  • 适用范围:系统所有用户和所有仓库
  • 查看/设置命令git config --system

2. 用户级别配置

  • 配置文件位置~/.gitconfig(MacOS/Linux)或 C:\Users\用户名\.gitconfig(Windows)
  • 适用范围:当前用户的所有仓库
  • 查看/设置命令git config --global

3. 仓库级别配置

  • 配置文件位置 :当前仓库目录下的 .git/config
  • 适用范围:仅当前仓库
  • 查看/设置命令git config --local(或不带参数)

查看当前代理配置

bash 复制代码
# 查看所有级别配置
git config --list --show-origin

# 查看用户级别代理配置
git config --global --get http.proxy
git config --global --get https.proxy

# 查看当前仓库代理配置
git config --get http.proxy
git config --get https.proxy

设置代理示例

bash 复制代码
# 设置 HTTP 代理(用户级别)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy https://127.0.0.1:7890

# 设置 SOCKS5 代理
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

# 为特定域名设置代理
git config --global http.https://github.com.proxy http://127.0.0.1:7890

# 移除代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy

SSH 代理配置

SSH 代理配置不在 Git 配置文件中,而是在 ~/.ssh/config 文件中:

bash 复制代码
# 编辑 SSH 配置文件
vim ~/.ssh/config

# 添加代理配置
Host github.com
    HostName github.com
    User git
    ProxyCommand nc -X 5 -x 127.0.0.1:7890 %h %p  # SOCKS5 代理
    # 或使用 HTTP 代理
    # ProxyCommand nc -X connect -x 127.0.0.1:7890 %h %p

通过这些配置,您可以根据需要为 Git 设置不同级别的代理,以满足不同场景的需求。

相关推荐
如意.7596 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
用户91868612868711 小时前
Git 版本控制完全指南:从入门到精通
git
ricky_fan12 小时前
(OpenAI)Codex 安装、部署使用方式
python·macos·conda·vim
简离13 小时前
Git 一次性清理已跟踪但应忽略文件
前端·git
Drone_xjw13 小时前
【环境搭建】Windows 10上使用Docker搭建本地Git仓库(Gitea)完整教程
windows·git·docker
疯狂成瘾者14 小时前
git学习目录
git·学习
曾几何时`15 小时前
Git——自用手册
git
音源部落16 小时前
Cubase15 R2R/VR一键安装完整版本下载安装Nuendo 14最新版本下载安装支持Win/Mac 双系统版本加104G原厂音源Mac系统不关SIP安装编曲软件Cubase 15.0.10下载
macos·vr·cubase·cubase15·nuendo·nuendo14
新镜19 小时前
【git】 曾经合入的文件被删除,再次合入时,相同的文件路径并不会自动合入
git
console.log('npc')19 小时前
git commit之后,想撤销commit
git