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 设置不同级别的代理,以满足不同场景的需求。

相关推荐
程序员小崔日记10 小时前
如何将代码轻松上传到 Gitee?Git 使用全攻略!
git·gitee·上传
Bigger1 天前
为什么你的 Git 提交需要签名?—— Git Commit Signing 完全指南
git·开源·github
DianSan_ERP2 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet
红豆子不相思2 天前
Tomcat 环境搭建与集群实战
服务器·git·tomcat
杰哥技术分享2 天前
Git 仓库迁移技术文档:从 CODING.net 迁移至腾讯云 CNB
git
梅孔立2 天前
Ansible 100 台服务器一键管控实战 进阶版
服务器·git·ansible
harmful_sheep2 天前
mac生效的终端查看
macos
qq_426003963 天前
git切换当前分支到远程分支
git
ON10N3 天前
100% 纯 Vibe Coding,我是怎么用 AI 撸出一个 VS Code 插件的
git·ai编程·visual studio code